当前位置: 移动技术网 > IT编程>开发语言>c# > C# 无边框窗体之窗体移动实现代码

C# 无边框窗体之窗体移动实现代码

2019年07月18日  | 移动技术网IT编程  | 我要评论

点击窗体任意位置移动窗体:

需要添加命名空间:

using system.runtime.interopservices;

复制代码 代码如下:

private const int wm_nclbuttondown = 0x00a1;
private  const int htcaption = 2;
[dllimport("user32.dll", charset = charset.unicode)]
public static extern intptr sendmessage(intptr hwnd, int wmsg, intptr wparam, intptr lparam);
[dllimport("user32.dll", charset = charset.unicode)]
public static extern bool releasecapture();

protected override void onmousedown( mouseeventargs e )
{
    base.onmousedown( e );
    if (e.button == mousebuttons.left)  // 按下的是鼠标左键             
    {
        releasecapture();   // 释放捕获                
        sendmessage(this.handle, wm_nclbuttondown, (intptr)htcaption, intptr.zero);    // 拖动窗体             
    }
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网