在我的C# WinForms应用程序中,我有一个主窗口,其中默认控件被隐藏。
因此,为了让它可以移动,我在主窗口中添加了以下内容:
private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
private const int WM_NCLBUTTONDBLCLK = 0x00A3;
protected override void WndProc(ref Message message)
{
if (message.Msg == WM_NCLBUTTONDBLCLK)
{
message.Result = IntPtr.Zero;
return;
}
base.WndProc(ref message);
//Allow window to move
if (message.Msg == WM_NCHITTEST && (int)message.Result == HTCLIENT)
message.Result = (IntPtr)HTCAPTION;
}
我有一个WPF应用程序,在其中我还隐藏了默认控件,我想做同样的事情。我看到主窗口派生自“Window”,因此上面的代码不起作用。在WPF中我该如何做到这一点?
protected override void OnMouseDown(MouseButtonEventArgs e){if (e.ChangedButton == MouseButton.Left) DragMove();}
。 - Gray Programmerz