Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove minimize and maximize buttons from a resizable window?

WPF doesn't provide the ability to have a window that allows resize but doesn't have maximize or minimize buttons. I'd like to able to make such a window so I can have resizable dialog boxes.

I'm aware the solution will mean using pinvoke but I'm not sure what to call and how. A search of pinvoke.net didn't turn up any thing that jumped out at me as what I needed, mainly I'm sure because Windows Forms does provide the CanMinimize and CanMaximize properties on its windows.

Could someone point me towards or provide code (C# preferred) on how to do this?

like image 870
Nidonocu Avatar asked Dec 04 '08 04:12

Nidonocu


People also ask

How do you remove minimize and maximize buttons in Excel?

Alternative Method to Hiding/Showing the MenuRight-click over the titles of the menu and select the Minimize the Ribbon option. To make it full-size again, right-click over the titles of the menu and select the Minimize the Ribbon option again.

How remove maximize and minimize button in WPF?

In WPF you can indeed set the WindowStyle property of a Window to System. Windows. WindowStyle. ToolWindow to get rid of the minimize and maximize buttons completely, but the window will then look slightly different compared to when the property is set to its default value of SingleBorderWindow.


1 Answers

I've stolen some code I found on the MSDN forums and made an extension method on the Window class, like this:

internal static class WindowExtensions {     // from winuser.h     private const int GWL_STYLE      = -16,                       WS_MAXIMIZEBOX = 0x10000,                       WS_MINIMIZEBOX = 0x20000;      [DllImport("user32.dll")]     extern private static int GetWindowLong(IntPtr hwnd, int index);      [DllImport("user32.dll")]     extern private static int SetWindowLong(IntPtr hwnd, int index, int value);      internal static void HideMinimizeAndMaximizeButtons(this Window window)     {         IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;         var currentStyle = GetWindowLong(hwnd, GWL_STYLE);          SetWindowLong(hwnd, GWL_STYLE, (currentStyle & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX));     } } 

The only other thing to remember is that for some reason this doesn't work from a window's constructor. I got around that by chucking this into the constructor:

this.SourceInitialized += (x, y) => {     this.HideMinimizeAndMaximizeButtons(); }; 

Hope this helps!

like image 106
Matt Hamilton Avatar answered Sep 22 '22 14:09

Matt Hamilton