以下是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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。