Question

I want to prevent the user from maximizing the Windows Form to full screen so I have disabled the Maximize button. However, I want to be able to have the user 'restore' the Form. When they click the Restore button I want it to show a different, smaller, minified, form, which will show them a maximize button which will return the use to the original form.

Is there a way to do this?

Thanks.

edit: You don't understand, I'm not preventing the user from resizing the form. Whats happening is when the click the restore button, it will hide the form and open a new one with less controls on it. When they click maximize on the smaller form, it will return to the original form.

Was it helpful?

Solution

I looked at a similar problem to this at work and the only solutions I could find involved setting undocumented window styles, which I was not inclined to do.

Therefore the best solution to your problem I would think would be to hide the current minimize/maximize/restore buttons and add your own using some ownerdraw or other commands.

Looking at this from a user interaction perspective I would want the minimize/maximize/restore buttons to do exactly the same thing for your application as they do for all others. Overriding that functionality would create confusion for your users, hence why I would recommend creating different buttons either on the title bar or somewhere else on your interface that perform this function.

OTHER TIPS

FWIW, the right answer is to make your form resize properly, adapting to any window size and not to constrain the user to what looks right on your display at your resolution and your font size. Non-resizeable windows are one of the most annoying things I encounter in an application (Windows itself is full of them).

You can set the MaximumSize and MinimumSize and enable the maximize button to get this kind of effect.

I had a similar situation recently, and from a UI design perspective, found a good example in Windows Media Player. It leaves the Minimise, Maximise and Restore buttons as they are, and has a separate button on the bottom right for "Switch to Compact Mode". And in the mini/compact mode, the same button toggles to "Switch to Full Mode". Another alternative example is Skype, which has an additional system icon button just left of the standard minimise button, that toggles between Compact and Standard modes.

(If I had the privilege, I would've preferred to put this as a comment to add to Daemin's accepted answer, still relatively new to StackOverflow)

'Restoring' a form fires the Resize event where you can check if the parent form is no longer FormWindowState.Maximized. If not, you can open the child form and hide the parent.

To reverse this, you can 'maximize' the child form by hiding (or disposing) it, then un-hide and set the parent form to FormWindowState.Maximized.

The only problem that I can see with this method is that the Resize event will likely fire several times before the form reaches a Maximumized state. A flag may be needed to ignore these until the form goes from the current state to the desired state, which can cause an infinite loop.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top