FormMove.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using FileManager;
  2. using MeasureData;
  3. using MeasureThread;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Configuration;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Runtime.InteropServices;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. using static MeasureThread.ThreadStatusEventArgs;
  17. namespace HOZProject
  18. {
  19. public partial class FormMove : Form
  20. {
  21. public FormMove()
  22. {
  23. InitializeComponent();
  24. }
  25. #region 拖动无窗体的控件
  26. [DllImport("user32.dll")]//拖动无窗体的控件
  27. public static extern bool ReleaseCapture();
  28. [DllImport("user32.dll")]
  29. public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  30. public const int WM_SYSCOMMAND = 0x0112;
  31. public const int SC_MOVE = 0xF010;
  32. public const int HTCAPTION = 0x0002;
  33. private void FormHOZMain_MouseDown(object sender, MouseEventArgs e)
  34. {
  35. if (this.WindowState == FormWindowState.Normal)
  36. {
  37. //拖动窗体
  38. ReleaseCapture();
  39. SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  40. }
  41. }
  42. private void Form_MouseDown(object sender, MouseEventArgs e)
  43. {
  44. if (this.WindowState == FormWindowState.Normal)
  45. {
  46. //拖动窗体
  47. ReleaseCapture();
  48. SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  49. }
  50. }
  51. #endregion
  52. private void FormMove_Load(object sender, EventArgs e)
  53. {
  54. //加载窗口移动事件
  55. this.MouseDown += new MouseEventHandler(Form_MouseDown);
  56. }
  57. }
  58. }