.ClientSize.Height) / 2);
93 }
94
95 // Translate the location so that we can use form-relative coordinates to draw on the control.
96 if (control != owner)
97 e.Graphics.TranslateTransform(-location.X, -location.Y);
98
99 // Fire a paint event.
100 OnPaint(sender, e);
101 }
102
103 private void OnPaint(object sender, PaintEventArgs e)
104 {
105 // Fire a paint event.
106 // The paint event will be handled in Form1.graphicalOverlay1_Paint().
107
108 if (Paint != null)
109 Paint(sender, e);
110 }
111 }
112 }
113
114 namespace System.Windows.Forms
115 {
116 using System.Drawing;
117
118 public static class Extensions
119 {
120 public static Rectangle Coordinates(this Control control)
121 {
122 // Extend System.Windows.Forms.Control to have a Coordinates property.
123 // The Coordinates property contains the control's form-relative location.
124 Rectangle coordinates;
125 Form form = (Form)control.TopLevelControl;
126
127 if (control == form)
128 coordinates = form.ClientRectangle;
129 else
130 coordinates = form.RectangleToClient(control.Parent.RectangleToScreen(control.Bounds));
131
132 return coordinates;
133 }
134 }
135 }
最后的话
如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星星吧
|