Commit 5eb997d3 HZH

move form

1 个父辈 a50aeeef
...@@ -37,6 +37,7 @@ namespace HZH_Controls.Forms ...@@ -37,6 +37,7 @@ namespace HZH_Controls.Forms
public FrmBack() public FrmBack()
{ {
InitializeComponent(); InitializeComponent();
InitFormMove(this.panTop);
} }
private void btnBack1_btnClick(object sender, EventArgs e) private void btnBack1_btnClick(object sender, EventArgs e)
......
...@@ -10,6 +10,7 @@ using System.Data; ...@@ -10,6 +10,7 @@ using System.Data;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
...@@ -466,5 +467,44 @@ namespace HZH_Controls.Forms ...@@ -466,5 +467,44 @@ namespace HZH_Controls.Forms
} }
#endregion #endregion
#region 窗体拖动 English:Form drag
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
/// <summary>
/// 通过Windows的API控制窗体的拖动
/// </summary>
/// <param name="hwnd"></param>
public static void MouseDown(IntPtr hwnd)
{
ReleaseCapture();
SendMessage(hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
#endregion
/// <summary>
/// 在构造函数中调用设置窗体移动
/// </summary>
/// <param name="c">拖动控件,一般为标题栏</param>
protected void InitFormMove(params Control[] cs)
{
foreach (Control c in cs)
{
if (c != null && !c.IsDisposed)
c.MouseDown += c_MouseDown;
}
}
void c_MouseDown(object sender, MouseEventArgs e)
{
MouseDown(this.Handle);
}
} }
} }
...@@ -25,6 +25,7 @@ namespace HZH_Controls.Forms ...@@ -25,6 +25,7 @@ namespace HZH_Controls.Forms
bool blnisEnterClose = true) bool blnisEnterClose = true)
{ {
InitializeComponent(); InitializeComponent();
InitFormMove(this.lblTitle);
if (!string.IsNullOrWhiteSpace(strTitle)) if (!string.IsNullOrWhiteSpace(strTitle))
lblTitle.Text = strTitle; lblTitle.Text = strTitle;
lblMsg.Text = strMessage; lblMsg.Text = strMessage;
......
...@@ -52,6 +52,7 @@ namespace HZH_Controls.Forms ...@@ -52,6 +52,7 @@ namespace HZH_Controls.Forms
public FrmWithTitle() public FrmWithTitle()
{ {
InitializeComponent(); InitializeComponent();
InitFormMove(this.lblTitle);
} }
private void btnClose_MouseDown(object sender, MouseEventArgs e) private void btnClose_MouseDown(object sender, MouseEventArgs e)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!