C#form 窗体去除标题栏,以及拖动无标题栏的窗体?
4个回答
展开全部
可以在Form的MouseDown事件里,执行两个API函数,模拟点击窗体Title的效果
以下是我的测试代码,希望对你有所帮助
private const int WM_NCLBUTTONDOWN = 0xA1;
private const int HT_CAPTION = 0x2;
[DllImport("user32.dll")]
private extern static bool ReleaseCapture();
[DllImport("user32.dll")]
private extern static int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
void Form3_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();//释放窗体的鼠标焦点
SendMessage(this.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
//模拟点击窗体的Title
}
}
以下是我的测试代码,希望对你有所帮助
private const int WM_NCLBUTTONDOWN = 0xA1;
private const int HT_CAPTION = 0x2;
[DllImport("user32.dll")]
private extern static bool ReleaseCapture();
[DllImport("user32.dll")]
private extern static int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
void Form3_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();//释放窗体的鼠标焦点
SendMessage(this.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
//模拟点击窗体的Title
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-03-28
展开全部
这样就可以了: 1、去掉窗体边框 FormBorderStyle None 2、 拖动无标题栏窗口 [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; private void frmLogin_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-03-27
展开全部
需要修改属性就可以搞定
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询