hollow,欢迎来到爱不绝迹的博客园!

窗体去掉边框后不能拖动的问题

在C# WinForm中,边框不显示就会造成窗体无法拖动的情况,把下边的代码添加上去就可以解决。

1.导入命名空间
using System.Runtime.InteropServices;
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);
private void pictureBox2_Click(object sender, EventArgs e)
{
    Application.Exit();
}

private void pictureBox4_Click(object sender, EventArgs e)
{
    this.WindowState = FormWindowState.Minimized;
}
在窗体的MouseDown事件中编写如下代码
private void zcmmForm_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        ReleaseCapture(); SendMessage(Handle, 0xA1, 0x02, 0);
    }
}

posted @ 2015-05-31 18:21  爱不绝迹  阅读(1361)  评论(0编辑  收藏  举报