MSDN > 論壇首頁 > Windows Presentation Foundation (WPF) > Hide Maximize/Minimze buttons?
發問發問
 

已答覆Hide Maximize/Minimze buttons?

  • 2009年7月2日 下午 10:51Kofoed 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Is there a way to hide the max/min buttons for the window?  I know you can use ToolWindow, but I'm having some problems using that style (it gets lost in the ALT-TAB menu) so I need a different way.  And I don't really want to rewrite the window chrome or redraw the borders if I don't have to.

解答

  • 2009年7月3日 上午 12:01noorbakhsh 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    Kofoed,
    If you also don't want to resize the window, a  ResizeMode="NoResize" will do it. It will remove them, but then, no resizing either.

    Hope this helps.
    noorbakhsh
    • 已標示為解答Kofoed 2009年7月6日 下午 04:11
    •  

所有回覆

  • 2009年7月3日 上午 12:01noorbakhsh 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    Kofoed,
    If you also don't want to resize the window, a  ResizeMode="NoResize" will do it. It will remove them, but then, no resizing either.

    Hope this helps.
    noorbakhsh
    • 已標示為解答Kofoed 2009年7月6日 下午 04:11
    •  
  • 2009年7月4日 上午 06:00harjohn 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     


    Hi,

    put this line of code after InitializeComponent

    this

    .WindowStyle = WindowStyle.None;


    hope solve ur problem


    Harshad..... Always 4 U
  • 2009年7月4日 上午 06:03harjohn 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Hi,

    put this line of code after InitializeComponent()


    this.WindowStyle = WindowStyle.None;


    Hope Solve ur Problem............

    Harshad..... Always 4 U
  • 2009年7月4日 上午 10:18John Simmons - outlaw programmer 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    I don't understand why *all* resizing is disabled just because the min/max buttons are removed from the titlebar...


  • 2009年7月6日 下午 04:39Zhi-Xin YeMSFT, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     包含代碼
    Hi Kofoed,

    You can remove the WS_MAXIMIZEBOX and WS_MINIMIZEBOX from the window style via P/Invoke.

    [DllImport("user32.dll", SetLastError = true)]
            static extern int GetWindowLong(IntPtr hWnd, int nIndex);
    
            [DllImport("user32.dll")]
            static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
    
            private const int GWL_STYLE = -16;
            private const int WS_MINIMIZEBOX = 0x20000;
            private const int WS_MAXIMIZEBOX = 0x10000;
    
            void Window5_Loaded(object sender, RoutedEventArgs e)
            {
                IntPtr hwnd = new WindowInteropHelper(this).Handle;
    
                long windowLong = GetWindowLong(hwnd, GWL_STYLE);
    
                windowLong = windowLong &~ WS_MAXIMIZEBOX;
                windowLong = windowLong &~ WS_MINIMIZEBOX;
    
                SetWindowLong(hwnd, GWL_STYLE, (int)windowLong);
            }
    


    Best Regards,
    Zhi-Xin
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.