class="dp-c" style="font: 12px/26px Consolas, 'Courier New', Courier, mono, serif; list-style: decimal; margin: 0px 0px 1px 45px !important; padding: 0px; border: currentColor; text-align: left; color: #5c5c5c; text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; font-size-adjust: none; font-stretch: normal; background-color: #ffffff; -webkit-text-stroke-width: 0px;" start="1">
- private void MainForm_Load(object sender, EventArgs e)
- {
-
- MouseMove += Form_MouseMove;
- MouseDown += Form_MouseDown;
- }
- private Point _mousePoint;
- private void Form_MouseMove(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- Top = MousePosition.Y - _mousePoint.Y;
- Left = MousePosition.X - _mousePoint.X;
- }
- }
- private void Form_MouseDown(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- _mousePoint.X = e.X;
- _mousePoint.Y = e.Y;
- }
- }
如果窗体有标题
Top -= SystemInformation.CaptionHeight;
如果有边框
Top -= SystemInformation.FormBorderSize.Height
Left -= SystemInformation.FormBorderSize.Width