现在的位置: 首页 > 综合 > 正文

WPF中代码画箭头

2011年03月15日 ⁄ 综合 ⁄ 共 1724字 ⁄ 字号 评论关闭

本文没什么内容,主要是一些代码的集合;

 

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;
        }
    }

 

 

 

抱歉!评论已关闭.