C#设置窗体可以移动
作者:互联网
#region 使窗体可以移动的代码
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
#endregion //这些在空白的公共区域地方添加
//控制区域 用MouseDown控件
private void Frm_Login_MouseDown(object sender, MouseEventArgs e)
{
//拖动窗体
this.Cursor = System.Windows.Forms.Cursors.Hand;//改变鼠标样式
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
this.Cursor = System.Windows.Forms.Cursors.Default;
}
------------------------------输入按键回车触发按键
switch (e.KeyCode)
{
case Keys.Enter:
break;
default:
break;
}
标签:const,C#,DllImport,MOVE,int,窗体,移动,public 来源: https://blog.csdn.net/qq_56040798/article/details/123602303