[英]Disable Minimize Button, but Keep Cross and Maximize Buttons - WPF, C#
I'd like to know how to disable the Minimize button, but keep the Maximize/Restore button and the Close button (the red "X"). 我想知道如何禁用“最小化”按钮,但是保留“最大化/还原”按钮和“关闭”按钮(红色的“ X”)。
Here's an image of what I want my window's buttons on the top-right to look like: 这是我希望右上角的窗口按钮看起来像的图像:
You may need to use PInvoke here. 您可能需要在此处使用PInvoke。 Basically you're importing SetWindowLong and GetWindowLong functions and setting corresponding flags to Win API window using it's handle(hwnd) 基本上,您要导入SetWindowLong和GetWindowLong函数,并使用其handle(hwnd)将相应的标志设置为Win API窗口
private const int GWL_STYLE = -16;
private const int WS_MINIMIZE = -131073;
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
private static void CanMinimize(Window w)
{
var hwnd = new WindowInteropHelper(w).Handle;
long value = GetWindowLong(hwnd, GWL_STYLE);
SetWindowLong(hwnd, GWL_STYLE, (int)(value & ~WS_MINIMIZE));
}
Blablablaster is basically right -- you need to P/Invoke a couple of Windows API calls -- but the following TechNet article also describes when/where you should make the call to the Windows API: Blablablaster基本上是正确的 - 你需要P / Invoke几个Windows API调用 - 但是下面的TechNet文章还描述了你应该在何时/何地调用Windows API:
WPF: Disabling or Hiding the Minimize, Maximize or Close Button Of a Window WPF:禁用或隐藏窗口的最小化,最大化或关闭按钮
Hope this helps. 希望这可以帮助。
Here is how I do it 这是我的方法
Private Sub WindowAddChange_StateChanged(sender As Object, e As EventArgs) Handles Me.StateChanged
If sender.windowstate = WindowState.Minimized Then
Me.WindowState = WindowState.Normal
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.