.NET Framework Developer Center > .NET Development Forums > Windows Presentation Foundation (WPF) > How do you disable Minimize, Maximize, Close buttons + remove app icon on a WPF window?
Ask a questionAsk a question
 

AnswerHow do you disable Minimize, Maximize, Close buttons + remove app icon on a WPF window?

  • Wednesday, October 04, 2006 7:21 PMFriedrich B Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    How do you disable Minimize, Maximize, Close buttons + remove app icon on a WPF window?  Any help doing this would be appreciated.

    Friedrich Brunzema

     

Answers

All Replies

  • Wednesday, October 04, 2006 7:31 PMZhou Yong Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Set the Window.WindowStyle property to WindowStyle.None.

    Sheva
  • Thursday, October 05, 2006 11:12 AMFriedrich B Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Sheva,

    I just tried this - it does a bit too much, removing the whole window title and border.  I am trying to mimick a normal modal dialog with no icon in the title bar, and no minimize/maximize, possibly no close button.

    Friedrich

  • Thursday, October 05, 2006 11:17 AMFriedrich B Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I just tried setting the WindowStyle to SingleBorderWindow - this is almost what I want: I would like the possibilty of showing/hiding the Window Icon in the titlebar and the close button.

    Friedrich

  • Thursday, June 14, 2007 2:24 PMLuke R Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Seems this was overlooked in WPF.  Shouldn't there be an equivilent of the MinimizeBox and MaximizeBox properties that are present in Windows Forms.

     

    Any ideas on a workaround to disable the minimize button and leave the maximize and close button on the window?

  • Saturday, June 16, 2007 3:52 AMLuke R Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Can someone comment on this from MSFT?  What is the bext practise for disabling the Minimize / Maximize buttons when using a WPF window?  I look forward to a response fro MSFT

     

    Thanks

  • Monday, June 18, 2007 7:22 PMHamid Mahmood - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer

    Disabling Minimize, Maximize buttons:

     

    This can be achieved by setting Window.ResizeMode property to ResizeMode.NoResize.  It will disable the minimize and maximize buttons.  Furthermore, the window will not resize by mouse click+drag.

     

    Not showing Icon and Close button:

     

    Unfortunately, this feature is not available in WPF.  To achieve this, you can try setting the WS_EX_DLGMODALFRAME window style by calling [Get/Set]WindowLong (pInvoking in to Win32) from the SourceInitialized event on the Window class.

    • Proposed As Answer byJeffHall345 Saturday, November 22, 2008 12:35 AM
    •  
  • Friday, July 06, 2007 3:09 AMLuke R Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Great!  It is possible to disable the minimize and maximize using  [Get/Set]WindowLong so that has resolved the issue.  Thanks!
  • Friday, July 20, 2007 6:50 PMYves Rochon Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    If anyone would be kind enough to show how to use [Get/Set]WindowLong, it would be greatly appreciated!
  • Monday, July 23, 2007 5:36 AMLuke R Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    <DllImport("user32.dll")> _

    Private Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer

    End Function

     

    <DllImport("user32.dll")> _

    Private Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer

    End Function

     

    Private Const GWL_STYLE As Integer = (-16)

    Private Sub RemoveControlBoxes()

    '

    Dim hwnd As IntPtr = New Interop.WindowInteropHelper(Me).Handle

    Dim windowLong As Long = GetWindowLong(hwnd, GWL_STYLE)

    windowLong = windowLong And -131073 And -65537

    SetWindowLong(hwnd, GWL_STYLE, CInt(windowLong))

    '

    End Sub

     

     

    The above VB.NET code should remove the Minimize and Max. control buttons within the Window frame.  Also, pinvoke.net is a handy resource for future reference.

  • Wednesday, October 31, 2007 11:44 AMshajipd Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
  • Tuesday, May 26, 2009 3:04 PMZest4Quest Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Hamid,
      I wanted to remove the Close button,but retain the Title bar..Based on the solution you gave here i tried the code and i see that the min and maximize buttons are gone. But could you please show me the code to remove the Close button while retaining the Title bar?
    Thanks
  • Tuesday, June 16, 2009 11:52 AMAnthony F Steele Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hamid says "To Disable Maximize and Minimize, set Window.ResizeMode property to ResizeMode.NoResize."

    Ok, I don't want to stop all resizing.
    What I want to do is allow resizing (between the min and max dimensions) but no maximising or minimising. How do I go about that?
  • Monday, November 02, 2009 9:55 PMRichard Morrison Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Certainly the Minimize button should be disabled when the window is not resizable, but I should still be able to turn off the button and keep my window resizable.

    Second, the minimize on a modal dialog owned by main window behaves very poorly. The dialog minimizes, focus changes to another application, say Live Messenger, but the main window of the application remains in the background and is disabled. Now if the Messenger isn't maximized, the disabled main window shows behind it and looks for all purposes like it ready to go - except its disabled.

    This will trip up my users. I need to be able to turn the button off with out resorting to resize functionality on the dialog.