-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawRectangle_Foo_1.cs
75 lines (60 loc) · 1.98 KB
/
DrawRectangle_Foo_1.cs
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
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class ang : Form
{
bool isMove = false;
private Rectangle m_Rect;
private Point m_LastMSPoint;
public ang()
{
InitializeComponent();
DoubleBuffered = true;
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true);
m_Rect = new Rectangle(10, 10, 50, 30);
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.FillRectangle(SystemBrushes.ControlDark, this.m_Rect);
e.Graphics.DrawRectangle(SystemPens.ControlDarkDark, this.m_Rect);
//Rectangle r = e.ClipRectangle;
//this.label1.Text = r.X + "," + r.Y;
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (m_Rect.Contains(e.Location))
{
this.m_LastMSPoint = e.Location;
isMove = true;//注意要加在这里
Cursor = Cursors.SizeAll;
}
else
{
return;
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.Button != MouseButtons.Left)
{
return;
}
if (isMove == true)
{
this.label1.Text = m_LastMSPoint.X + "," + m_LastMSPoint.Y + " ; " + e.Location.X + "," + e.Location.Y;
this.m_Rect.Offset(e.Location.X - this.m_LastMSPoint.X, e.Location.Y - this.m_LastMSPoint.Y);
this.Invalidate();
this.m_LastMSPoint = e.Location;
}
}
protected override void OnMouseUp(MouseEventArgs e)
{
isMove = false;
Cursor = Cursors.Default;
}
}
}