将拖动行为添加到FormBorderStyle设置为None的表单中 [英] Add drag behavior to a form with FormBorderStyle set to None
本文介绍了将拖动行为添加到FormBorderStyle设置为None的表单中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
C#-使无边界表单可移动吗?
如果我将表单的 FormBorderStyle
设置为 None
,则会丢失表单的拖动行为,这与预期的一样。
If I set my form's FormBorderStyle
to None
, I lose the drag behavior of the form, as expected.
我在表单顶部添加了一个自定义栏,我希望它保持这种状态,现在可以将表单保持在此模式下并具有(或写入)拖动行为?
I've added a custom bar to the top of my form and I like it to stay that way, now is it possible to keep the form in this mode and have (or write) drag behavior?
如果可能的话,我应该怎么做。我真的希望找到一个是的,可能的答案。:)
If it's possible, how should I do so. I really hope to find a Yes it's possible answer. :)
推荐答案
private const Int32 WM_NCHITTEST = 0x84;
private const Int32 HTCLIENT = 0x1;
private const Int32 HTCAPTION = 0x2;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_NCHITTEST)
{
base.WndProc(ref m);
if ((Int32)m.Result == HTCLIENT)
m.Result = (IntPtr)HTCAPTION;
return;
}
base.WndProc(ref m);
}
这篇关于将拖动行为添加到FormBorderStyle设置为None的表单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文