如何从最大化FormBorderStyle.FixedToolWindow的窗口中停止双击窗口标题栏?

我很生气,我答应了一个用户无法resize的固定窗口,但当然他们可以双击标题栏以最大化这个“不可调整的”窗口。 我该怎么办呢? 我可以使用winforms代码执行此操作,还是必须转到Win32?

谢谢!

您可以将窗体的MaximizeBox属性设置为false

您可以禁用标题栏上的双击消息(或更改最大化窗口的默认行为)。 它适用于任何FormBorderStyle:

 private const int WM_NCLBUTTONDBLCLK = 0x00A3; //double click on a title bar aka non-client area of the form protected override void WndProc(ref Message m) { if (m.Msg == WM_NCLBUTTONDBLCLK) { m.Result = IntPtr.Zero; return; } base.WndProc(ref m); } 

MSDN来源

干杯!

/// ///这是我们重写基本WIN32窗口过程,以防止鼠标移动窗体以及鼠标双击resize。 /// ///

  protected override void WndProc(ref Message m) { const int WM_SYSCOMMAND = 0x0112; const int SC_MOVE = 0xF010; const int WM_NCLBUTTONDBLCLK = 0x00A3; //double click on a title bar aka non-client area of the form switch (m.Msg) { case WM_SYSCOMMAND: //preventing the form from being moved by the mouse. int command = m.WParam.ToInt32() & 0xfff0; if (command == SC_MOVE) return; break; } if(m.Msg== WM_NCLBUTTONDBLCLK) //preventing the form being resized by the mouse double click on the title bar. { m.Result = IntPtr.Zero; return; } base.WndProc(ref m); } 

我知道我迟到了,可以帮助那些正在寻找相同的人。

 private const int WM_NCLBUTTONDBLCLK = 0x00A3; //double click on a title bar aka non-client area of the form private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { switch (msg) { case WM_NCLBUTTONDBLCLK: //preventing the form being resized by the mouse double click on the title bar. handled = true; break; default: break; } return IntPtr.Zero; } 

我刚刚在VB.Net中查看过它。 下面的代码对我有用。

 Private Const Win_FormTitleDoubleClick As Integer = 163 Protected Overrides Sub WndProc(ByRef m As Message) If m.Msg = Win_FormTitleDoubleClick Then m.Result = IntPtr.Zero Return End If MyBase.WndProc(m) End Sub 

注意:163是事件代码