本文没什么内容,主要是一些代码的集合;
1:WPF中后台代码画一条类似于箭头线的线条;
箭头线
// Fields
private double mArrowAngle = 0.17453292519943295;
private double mArrowLengh = 30.0;
// Methods
public override Geometry Create(double x1, double y1, double x2, double y2)
{
Point point = new Point(x1, y1);
Point point2 = new Point(x2, y2);
double num = Math.Atan((y2 - y1) / (x2 - x1));
double d = num - this.ArrowAngle;
double num3 = num + this.ArrowAngle;
int num4 = (x2 > x1) ? -1 : 1;
double x = x2 + ((num4 * this.ArrowLengh) * Math.Cos(d));
double y = y2 + ((num4 * this.ArrowLengh) * Math.Sin(d));
double num7 = x2 + ((num4 * this.ArrowLengh) * Math.Cos(num3));
double num8 = y2 + ((num4 * this.ArrowLengh) * Math.Sin(num3));
Point point3 = new Point(x, y);
Point point4 = new Point(num7, num8);
PathGeometry geometry = new PathGeometry();
PathFigure figure = new PathFigure();
figure.IsFilled = true;
figure.StartPoint = point2;
Point[] points = new Point[] { point, point2, point3, point4, point2 };//从point2到point 然后在倒回来到point2,然后画箭头。及从point2到point3到point4到point2.....
PolyLineSegment segment = new PolyLineSegment(points, true);
figure.Segments.Add(segment);
geometry.Figures.Add(figure);
geometry.Freeze();
return geometry;
}
// Properties
public double ArrowAngle
{
get
{
return this.mArrowAngle;
}
set
{
this.mArrowAngle = value;
}
}
public double ArrowLengh
{
get
{
return this.mArrowLengh;
}
set
{
this.mArrowLengh = value;
}
}
private double mArrowAngle = 0.17453292519943295;
private double mArrowLengh = 30.0;
// Methods
public override Geometry Create(double x1, double y1, double x2, double y2)
{
Point point = new Point(x1, y1);
Point point2 = new Point(x2, y2);
double num = Math.Atan((y2 - y1) / (x2 - x1));
double d = num - this.ArrowAngle;
double num3 = num + this.ArrowAngle;
int num4 = (x2 > x1) ? -1 : 1;
double x = x2 + ((num4 * this.ArrowLengh) * Math.Cos(d));
double y = y2 + ((num4 * this.ArrowLengh) * Math.Sin(d));
double num7 = x2 + ((num4 * this.ArrowLengh) * Math.Cos(num3));
double num8 = y2 + ((num4 * this.ArrowLengh) * Math.Sin(num3));
Point point3 = new Point(x, y);
Point point4 = new Point(num7, num8);
PathGeometry geometry = new PathGeometry();
PathFigure figure = new PathFigure();
figure.IsFilled = true;
figure.StartPoint = point2;
Point[] points = new Point[] { point, point2, point3, point4, point2 };//从point2到point 然后在倒回来到point2,然后画箭头。及从point2到point3到point4到point2.....
PolyLineSegment segment = new PolyLineSegment(points, true);
figure.Segments.Add(segment);
geometry.Figures.Add(figure);
geometry.Freeze();
return geometry;
}
// Properties
public double ArrowAngle
{
get
{
return this.mArrowAngle;
}
set
{
this.mArrowAngle = value;
}
}
public double ArrowLengh
{
get
{
return this.mArrowLengh;
}
set
{
this.mArrowLengh = value;
}
}
有事Q我:
姓名:颜昌钢
联系方式:yanchanggang@boco.com.cn
电话:13886086508
QQ:95550107
公司:亿阳集团武汉分公司
移动飞信:647360243