C# winform 无边框窗口 移动

给自己留个笔记, 在用wke做界面的时候. 往往需要把winform窗口设置成无边框

但是WebUI也需要移动窗口, 所以才把以前在易语言中用的方法翻译过来使用

设置无边框窗口

1
form属性设置 FormBorderStyle = None

引用

1
using System.Runtime.InteropServices;

声明DLL调用方法

1
2
3
4
5
6
7
8
9
//窗口是否最大化, 最大化返回true 否则false
[DllImport("user32.dll")]
public static extern bool IsZoomed(IntPtr hwnd);
//释放捕获
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
//发送消息
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

为”鼠标按下(MouseDown)”事件添加功能代码

1
2
3
4
5
6
7
8
9
10
11
12
private void Login_MouseDown(object sender, MouseEventArgs e)
{
//鼠标左键按下
if (e.Button == MouseButtons.Left)
{
if (IsZoomed(this.Handle) == false)
{
ReleaseCapture();
SendMessage(this.Handle, 161, 2, 0);
}
}
}

这里写图片描述
这样功能就实现辣


C# winform 无边框窗口 移动
http://edk24.com/2017/346f849c.html
作者
余小波
发布于
2017年9月28日
许可协议