WPF 鼠标左键捕获点,用polyline连接起来

WPF 鼠标左键捕获点,用polyline连接起来

 Polyline lines;
        Line dot;
        Polyline cach;
        public Window1()
        {
            InitializeComponent();
             
            lines=new Polyline();
            lines.Stroke =new SolidColorBrush(Colors.Black);
            canvas.Children.Add(lines);
             
            cach=new Polyline();
            cach.Stroke =new SolidColorBrush(Colors.Black);
             
            canvas.Children.Add(cach);
             
            dot=new Line();
            dot.Stroke =new SolidColorBrush(Colors.Black);
            dot.StrokeDashArray.Add(4);
            canvas.Children.Add(dot);
        }
         
        void Canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var point= e.GetPosition(canvas);
            lines.Points.Add(point);
        }
         
        void Canvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            cach.Points=lines.Points.Clone();
            cach.Points.Add(lines.Points[0]);
            lines.Points.Clear();
            dot.X1=dot.X2=dot.Y1=dot.Y2=0;
        }
        void Canvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (lines.Points.Count>0) {
                var point=lines.Points[lines.Points.Count-1];
                dot.X1=point.X;
                dot.Y1=point.Y;
                point= e.GetPosition(canvas);
                dot.X2=point.X;
                dot.Y2=point.Y;
            }
        }
上一篇:2021“MINIEYE杯”中国大学生算法设计超级联赛(10)1003. / HDU7079 Pty loves lines(bitset优化DP)


下一篇:Pty loves lines 题解(dp)