Silverlight里C#绘制Path的方法

以下是C#代码


CODE:C# Code

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 

namespace slArrow 
{ 
    public partial class Page : UserControl 
    { 
        public Page() 
        { 
            InitializeComponent(); 
            LayoutRoot.Loaded += new RoutedEventHandler(LayoutRoot_Loaded); 
        } 

        void LayoutRoot_Loaded(object sender, RoutedEventArgs e) 
        { 
            drawArrow(new Point(300, 300)); 
        } 

        public void drawArrow(Point endP) 
        { 
            double slopy; 
            double cosy; 
            double siny; 
            double Par = 8.0; 
            //slopy = Math.atan2((StartP.y-endP.y+20),(StartP.x-endP.x)); 
            slopy=3.1415926; 
            cosy = Math.Cos(slopy); 
            siny = Math.Sin(slopy); 

            PathGeometry aPathGeometry = new PathGeometry(); 
            arrowPath.Data = aPathGeometry; 

            aPathGeometry.Figures = new PathFigureCollection(); 

            PathFigure aPathFigure = new PathFigure(); 

            aPathFigure.StartPoint = endP; 

            LineSegment Line1 = new LineSegment(); 
            LineSegment Line2 = new LineSegment(); 
            LineSegment Line3 = new LineSegment(); 

            Point p1 = new Point(); 
            Point p2 = new Point(); 
            Point p3 = new Point(); 

            p1.X = endP.X + ( Par * cosy - ( Par / 2.0 * siny ) ); 
            p1.Y = endP.Y + ( Par * siny + ( Par / 2.0 * cosy ) ); 

            p2.X = endP.X + ( Par * cosy + Par / 2.0 * siny ); 
            p2.Y = endP.Y - ( Par / 2.0 * cosy - Par * siny ); 

            p3.X = endP.X; 
            p3.Y = endP.Y; 

            Line1.Point = p1; 
            Line2.Point = p2; 
            Line3.Point = p3; 

            aPathFigure.Segments.Add(Line1); 
            aPathFigure.Segments.Add(Line2); 
            aPathFigure.Segments.Add(Line3); 

            aPathGeometry.Figures.Add(aPathFigure); 
        } 
    } 
}

以下代码放在XAML文档里边

CODE:XAML Code

<UserControl x:Class="slArrow.Page" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300"> 
    <Grid x:Name="LayoutRoot" Background="White"> 
        <Path x:Name="arrowPath" Stroke="Red" StrokeThickness="4"/>        
    </Grid> 
</UserControl>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值