yangyin
2024-12-16 b4c867bf85d3edef5d084a3a26f13cbc6784bf58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace DPumpHydr.WinFrmUI.Volute
{
    public partial class DesignDraw1 : UserControl
    {
        public DesignDraw1()
        {
            Point start = new Point(20, 120);
            Point control1 = new Point(40, 90);
            Point control2 = new Point(60, 150);
            Point end1 = new Point(100, 180);
            Point control3 = new Point(120, 170);
            Point control4 = new Point(135, 190);
            Point end2 = new Point(150, 220);
 
            screenPoints = new List<Point> { start, control1, control2, end1, control3, control4, end2 };
        }
        List<Point> screenPoints;
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
 
 
 
 
            Graphics g = e.Graphics;
            if (_dragPointNO >= 0)
            {
                using (Pen penUn = new Pen(Color.Gray, 2f))
                using (SolidBrush penSelect = new SolidBrush(Color.Red))
                {
                    for (int i = 0; i < screenPoints.Count; i++)
                    {
                        var pt = screenPoints[i];
                        if (i == _dragPointNO)
                            g.FillEllipse(penSelect, pt.X - 4f, pt.Y - 4f, 8, 8);
                        else
                            g.DrawEllipse(penUn, pt.X - 4f, pt.Y - 4f, 8, 8);
                    }
 
                }
            }
            else
            {
 
                using (SolidBrush penBrush = new SolidBrush(Color.Black))
                {
                    foreach (var pt in screenPoints)
                    {
                        g.FillEllipse(penBrush, pt.X - 4f, pt.Y - 4f, 8, 8);
                    }
                }
 
            }
 
 
            using (Pen penCurve = new Pen(Color.Blue, 2f))
            {
                g.DrawBeziers(penCurve, screenPoints.ToArray());
            }
 
        }
        int _dragPointNO = -1;
        protected override void OnMouseClick(MouseEventArgs e)
        {
            base.OnMouseClick(e);
 
        }
 
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
 
            this.Cursor = Cursors.Default;
            if (_dragPointNO >= 0)
            {
                //鼠标未移除控件范围
                if (this.ClientRectangle.Contains(e.Location))
                {
                    screenPoints[_dragPointNO] = e.Location;
                    Invalidate();
                }
            }
            _dragPointNO = -1;
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
 
            _dragPointNO = -1;
            this.Cursor = Cursors.Default;
            //判断是否在点周围
            Rectangle r = new Rectangle(e.X - 5, e.Y - 5, 10, 10);
            for (int i = 0; i < screenPoints.Count; i++)
            {
                if (r.Contains(screenPoints[i]))
                {
                    _dragPointNO = i;
                    this.Cursor = Cursors.Hand;
                    Invalidate();
                    break;
                }
            }
        }
 
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
 
            if (_dragPointNO >= 0)
            {
                //鼠标未移除控件范围
                if (this.ClientRectangle.Contains(e.Location))
                {
                    screenPoints[_dragPointNO] = e.Location;
                    Invalidate();
                }
            }
        }
    }
}