views:

4245

answers:

8

In my application I need to temporarily gray out the minimize button of the main form. Any ideas how this can be achieved? I don't mind doing p/invokes to Win32 dlls.

Edit: Graying out the minimize button would be the preferred solution, but is there any other way of preventing the form from becoming minimized?

+8  A: 
form.MinimizeBox = false;

or if in the form scope

MinimizeBox = false;
Coincoin
This hides the minimize box, but does not gray it out.
Filip
Hmmm, strange. I tested it and it grays it out. It's still there, semi transparent and you can't click it.
Coincoin
Depends on your windows theme. If the minimize button is enabled, you get one image. If disabled, you get a different image. That image might be nothing, so then you don't even see a greayed-out button.
Eyal
+1  A: 

Just do MinimizeBox = false; in your form's code.

Will Dean
A: 

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

sebastian
That would work if there were such an event. :)
MusiGenesis
+1  A: 

Put this code in your form's Resize event:

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

This will make your form un-minimizable (DISCLAIMER: I do not advocate altering the standard behavior of windows in this way).

MusiGenesis
+1  A: 

Don't. Don't mess with my windows. They are mine, not yours. It is my computer and if I want to minimize, I should be able to. I can't think of, and have never been given, a good reason for doing this.

Kevin
I'm going to go with "nuclear power plant core monitoring software". If the author wants to make that window un-minimizable, I'm fine with it.
MusiGenesis
until the monitoring software is showing everything red-lining and the "emergency shutdown" button is located behind the monitoring software window
Kevin
For god's sake don't use C# WinForms for nuclear power stations!
Callum Rogers
A: 

Coincoin's answer is correct. MinimizeBox is also available as a property in the designer properties window.

@Kevin: While I appreciate the sentiment, that's not always a valid answer. If the application displays a modal dialog box by creating a new instance of a Form and then calling .ShowDialog() on it, you don't want the user to minimize that Form, because then all input on the main UI thread is blocked until that Form's modal status is satisfied. The user could potentially click on the main form and just get the "ding ding ding" unresponsive sound from Windows and not know what to do.

Rob
Setting MinimizeBox to false would usually suffice, but in my case the MaximizeBox is also hidden. When MinimizeBox is shown, the toolbar renders 3 buttons - minimize, grayed out maximize, close. But when when is set MinimizeBox to false, the minimize/maximize buttons aren't rendered anymore.
Filip
or they could need to see a piece of information behind the modal form to fill it out and want to minimize it to see that information better. Also, since this question may be viewed by newbie programmers, I wanted to put this advice out there for them.
Kevin
A: 

Read this from Joel Spolsky

benPearce
Bah. What if you have 10 menu items and the user can only use 1? You want the user to have to click on 9 items and see "sorry, can't use that one either"? So, to reiterate: bah.
MusiGenesis
There are other ways to indicate status: tool tips or icons, or remove the menu item altogether. The instant the user sees a greyed out control they are going to be wondering what they need to do to get it available.
benPearce
Tool tips on a menu? Bah. Menus suck, but if you're going to use them at least take advantage of the fact that everybody in the world knows how to use them, and use them normally. Oh, one other thing: bah.
MusiGenesis
Why are we even talking about menus in a question about the minimize button?
MusiGenesis
Sorry, Joel Spolsky, while smart, isn't the end-all be-all authority on user interface design. Giving this as a blanket statement and then saying "Joel Spolsky says" doesn't address the problem. You don't know, and neither does Joel, the business case behind the UI design.
Rob
It was only a suggestion, saying here is an opinion to take into consideration. Most people would be smart enough to take these on merit and apply them to their situation. It was not a blanket, one-size-fits-all comment.
benPearce
+4  A: 
Rob