移动窗口无边框 [英] Move window without border

查看:300
本文介绍了移动窗口无边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何移动,它没有边框的窗口。没有对应用程序没有空间,所有可用的web浏览器和的MenuStrip。我希望用户能够通过拖动菜单条移动窗口。我如何代码呢?我已经尝试了一些代码块我已经在网上找到,但他们没有工作。

How do I move a window that does not have a border. There is no empty space on the application, all that is available is a webbrowser and a menustrip. I would like the users to be able to move the window by dragging the menu strip. How do I code this? I have tried a few code blocks I have found online, but none of them worked.

推荐答案

This 代码项目的文章应该帮助你做到这一点。我这个没有问题,用我自己。这是它的JIST:

This Code Project article should help you accomplish this. I've used this myself with no problems. This is the jist of it:

public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;

[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();

private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{     
    if (e.Button == MouseButtons.Left)
    {
        ReleaseCapture();
        SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
    }
}

这基本上都会绝招窗口管理器思成它抓在WinForm的标题栏。

This will basically "trick" the window manager into thinking that it is grabbing the title bar of the winform.

要它应用到项目中,只使用从MenuStrip中MouseDown事件。

To apply it to your project, just use the MouseDown event from the MenuStrip.

这篇关于移动窗口无边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆