Browse Source

添加可拖动

章政 8 năm trước cách đây
mục cha
commit
036538ba17

+ 1 - 0
UAS-MES/FunctionCode/Make/Make_NewBadCode.Designer.cs

@@ -207,6 +207,7 @@
             this.headBar1.Size = new System.Drawing.Size(548, 32);
             this.headBar1.TabIndex = 98;
             this.headBar1.Title = null;
+            this.headBar1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.headBar1_MouseDown);
             // 
             // badgroup
             // 

+ 23 - 0
UAS-MES/FunctionCode/Make/Make_NewBadCode.cs

@@ -4,6 +4,7 @@ using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
+using System.Runtime.InteropServices;
 using System.Text;
 using System.Windows.Forms;
 using UAS_MES.DataOperate;
@@ -14,6 +15,22 @@ namespace UAS_MES.Make
 {
     public partial class Make_NewBadCode : Form
     {
+        //所有用到了headBar的部分都需要这段代码
+        [DllImport("user32.dll")]
+        public static extern bool ReleaseCapture();
+
+        [DllImport("user32.dll")]
+        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
+
+        [DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
+        public static extern int GetWindowLong(HandleRef hWnd, int nIndex);
+
+        [DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
+        public static extern IntPtr SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong);
+
+        public const int WM_SYSCOMMAND = 0x0112;
+        public const int SC_MOVE = 0xF010;
+        public const int HTCAPTION = 0x0002;
         /// <summary>
         /// 序列号
         /// </summary>
@@ -219,5 +236,11 @@ namespace UAS_MES.Make
             }
             WaitRejectList.EndUpdate();
         }
+
+        private void headBar1_MouseDown(object sender, MouseEventArgs e)
+        {
+            ReleaseCapture();
+            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
+        }
     }
 }

+ 1 - 0
UAS-MES/FunctionCode/Make/Make_NewMatainInf.Designer.cs

@@ -319,6 +319,7 @@
             this.headBar1.Size = new System.Drawing.Size(624, 32);
             this.headBar1.TabIndex = 0;
             this.headBar1.Title = "新增维修信息";
+            this.headBar1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.headBar1_MouseDown);
             // 
             // Make_NewMatainInf
             // 

+ 24 - 0
UAS-MES/FunctionCode/Make/Make_NewMatainInf.cs

@@ -4,6 +4,7 @@ using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
+using System.Runtime.InteropServices;
 using System.Text;
 using System.Windows.Forms;
 using UAS_MES.DataOperate;
@@ -14,6 +15,23 @@ namespace UAS_MES.Make
 {
     public partial class Make_NewMatainInf : Form
     {
+        //所有用到了headBar的部分都需要这段代码
+        [DllImport("user32.dll")]
+        public static extern bool ReleaseCapture();
+
+        [DllImport("user32.dll")]
+        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
+
+        [DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
+        public static extern int GetWindowLong(HandleRef hWnd, int nIndex);
+
+        [DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
+        public static extern IntPtr SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong);
+
+        public const int WM_SYSCOMMAND = 0x0112;
+        public const int SC_MOVE = 0xF010;
+        public const int HTCAPTION = 0x0002;
+
         /// <summary>
         /// 序列号
         /// </summary>
@@ -227,5 +245,11 @@ namespace UAS_MES.Make
             dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
             AddDataToListView(nr_name_lsv, dt);
         }
+
+        private void headBar1_MouseDown(object sender, MouseEventArgs e)
+        {
+            ReleaseCapture();
+            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
+        }
     }
 }