How to disable the minimize button in C #?

In my application, I need to temporarily omit the minimize button of the main form. Any ideas how this can be achieved? I do not mind doing p / invokes for the Win32 DLL.

Edit: turning off the minimize button would be the preferred solution, but is there any other way to prevent minimizing the shape?

+6
c # winforms minimize
source share
8 answers

I read your comment regarding my answer and was able to put together a more complete solution for you. I quickly ran and seemed to do what I wanted. Instead of inferring your winform forms from the form, output from this class:

using System; using System.Windows.Forms; using System.ComponentModel; namespace NoMinimizeTest { public class MinimizeControlForm : Form { private const int WM_SYSCOMMAND = 0x0112; private const int SC_MINIMIZE = 0xf020; protected MinimizeControlForm() { AllowMinimize = true; } protected override void WndProc(ref Message m) { if (!AllowMinimize) { if (m.Msg == WM_SYSCOMMAND) { if (m.WParam.ToInt32() == SC_MINIMIZE) { m.Result = IntPtr.Zero; return; } } } base.WndProc(ref m); } [Browsable(true)] [Category("Behavior")] [Description("Specifies whether to allow the window to minimize when the minimize button and command are enabled.")] [DefaultValue(true)] public bool AllowMinimize { get; set; } } } 

You can do a little more if you want to decide whether to allow minimization when sending a click, for example:

 using System; using System.Windows.Forms; using System.ComponentModel; namespace NoMinimizeTest { public class MinimizeControlForm : Form { private const int WM_SYSCOMMAND = 0x0112; private const int SC_MINIMIZE = 0xf020; protected MinimizeControlForm() { } protected override void WndProc(ref Message m) { if (m.Msg == WM_SYSCOMMAND) { if (m.WParam.ToInt32() == SC_MINIMIZE && !CheckMinimizingAllowed()) { m.Result = IntPtr.Zero; return; } } base.WndProc(ref m); } private bool CheckMinimizingAllowed() { CancelEventArgs args = new CancelEventArgs(false); OnMinimizing(args); return !args.Cancel; } [Browsable(true)] [Category("Behavior")] [Description("Allows a listener to prevent a window from being minimized.")] public event CancelEventHandler Minimizing; protected virtual void OnMinimizing(CancelEventArgs e) { if (Minimizing != null) Minimizing(this, e); } } } 

For more information about this window notification, see the MSDN article about it .

+11
source share
 form.MinimizeBox = false; 

or if in the field of view

 MinimizeBox = false; 
+10
source share

Just do MinimizeBox = false; in your form code.

+1
source share

Put this code in your form. Resize:

 if (this.WindowState == FormWindowState.Minimized) { this.WindowState = FormWindowState.Normal; } 

This will make your form not minimal (DISCLAIMER: I am not in favor of changing the standard behavior of windows this way).

+1
source share

You can also implement the Minimize event descriptor to cancel the command

0
source share

not to do. Do not confuse my windows. They are mine, not yours. This is my computer, and if I want to minimize it, I must be able to do it. I can not think of it and was never given, it was a good reason for this.

0
source share

The answer to the match is correct. MinimizeBox is also available as a property in the constructor properties window.

@Kevin: Although I appreciate the mood, this is not always the right answer. If the application displays a modal dialog box, creating a new instance of the form and then calling it .ShowDialog (), you do not want the user to minimize this form, because then all the input in the main stream of the user interface is blocked until the form is modal status is satisfied. The user can potentially click on the main form and simply get the "ding ding ding" sound immunity from Windows and not know what to do.

0
source share

just set the MinimizeBox property of your form to false. this will disable the minimize button, but the other buttons will remain functional.

0
source share

All Articles