如何当其FormBorderStyle属性设置为无移动Windows窗体? [英] How to move a Windows Form when its FormBorderStyle property is set to None?
问题描述
使用C#。结果
我试图移动表格
没有它的标题栏。结果
我上找到了一篇文章吧:<一href=\"http://www.$c$cproject.com/KB/cs/csharpmovewindow.aspx\">http://www.$c$cproject.com/KB/cs/csharpmovewindow.aspx
Using C#.
I am trying to move a Form
without its title bar.
I found an article about it on: http://www.codeproject.com/KB/cs/csharpmovewindow.aspx
它的工作原理,只要我不设置 FormBorderStyle
为无
。
It works as long as I do not set FormBorderStyle
as None
.
有没有一种方法,使其与这个属性设置为正常工作无
?
Is there a way to make it work with this property set as None
?
推荐答案
我知道这个问题是一岁多,但是我正在寻找试图记住我是如何在过去做到了。因此,对于别人的参考,最快捷,更简单的方式,然后上面的链接是重写的WndProc功能。
I know this question is over a year old, but I was searching trying to remember how I've done it in the past. So for anyone else's reference, the quickest and less complex way then the above link is to override the WndProc function.
/*
Constants in Windows API
0x84 = WM_NCHITTEST - Mouse Capture Test
0x1 = HTCLIENT - Application Client Area
0x2 = HTCAPTION - Application Title Bar
This function intercepts all the commands sent to the application.
It checks to see of the message is a mouse click in the application.
It passes the action to the base action by default. It reassigns
the action to the title bar if it occured in the client area
to allow the drag and move behavior.
*/
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case 0x84:
base.WndProc(ref m);
if ((int)m.Result == 0x1)
m.Result = (IntPtr)0x2;
return;
}
base.WndProc(ref m);
}
这将允许任何形式的点击和客户区域内拖动来移动。
This will allow any form to be moved by clicking and dragging within the client area.
这篇关于如何当其FormBorderStyle属性设置为无移动Windows窗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!