3

I'd like to know how to disable the Minimize button, but keep the Maximize/Restore button and the Close button (the red "X").

Here's an image of what I want my window's buttons on the top-right to look like:

enter image description here

Community
  • 1
  • 1
Bubbled86
  • 461
  • 2
  • 7
  • 17

4 Answers4

6

You may need to use PInvoke here. Basically you're importing SetWindowLong and GetWindowLong functions and setting corresponding flags to Win API window using it's handle(hwnd)

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
  • 3,238
  • 3
  • 31
  • 33
1

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:

WPF: Disabling or Hiding the Minimize, Maximize or Close Button Of a Window

Hope this helps.

Mal Ross
  • 4,551
  • 4
  • 34
  • 46
0

I don't think WPF provides a way to disable just the minimize button. What you can do is disable the complete title bar and create a custom title bar for yourself. Check this out.

Tanuj Wadhwa
  • 2,025
  • 9
  • 35
  • 57
0

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
Rob
  • 3,488
  • 3
  • 32
  • 27