您的位置:首页 > 其它

winform 窗体属性FormBorderStyle 为none时使窗体可以被移动

2017-11-15 09:40 519 查看
我们在做winform开发时 会觉得窗体的 最大化 关闭等按钮很丑 这时我们就会把窗体的属性FormBorderStyle设置为None 从而自定义按钮 但此时 窗体就不能够被移动了

下面贴一下 可以移动的代码

第一步:在程序中添加以下代码

·#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

第二步:在窗体的Mouse_Down事件中调用

private void Main_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;

}

OK了 窗体可以移动了

原文链接:http://blog.csdn.net/everlasting51/article/details/16827273
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: