Powered by: newtelligence dasBlog 1.9.6264.0
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
E-mail
Theme design by Christoph Herold
Sometimes, the developers of the .NET framework seem not to have thought things through. This is also the case with the windows.forms namespace concerning the maximizing of windows. When you have a fixed size dialog, you will probably also disable resizing using the SizeGripStyle property. Furthermore, you'll want to disable the maximize button, either by setting the MaximizeBox property to false, or by hiding the titlebar controls altogether using the ControlBox property.
This is all well, but I've noticed, that disabling all of these things doesn't disable maximizing of windows completely. When you double-click the titlebar of the window, you'll still be able to maximize it, probably making the contents of the form quite ugly. If you REALLY want to disable maximizing, you'll have to handle some window messages.
This is actually not that difficult. All you have to do is override the WndProc method and search for some constants in the windows API. What you'll need here are WM_SYSCOMMAND and SC_MAXIMIZE, both found in winuser.h. Then all there's left to do is implement the method as follows:
private const int WM_SYSCOMMAND = 0x0112; private const int SC_MAXIMIZE = 0xF030; protected override void WndProc(ref Message m) { if (m.Msg == WM_SYSCOMMAND) { if (((int)m.WParam & 0xFFF0) == SC_MAXIMIZE) { if (this.WindowState != FormWindowState.Normal) { this.WindowState = FormWindowState.Normal; } m.Result = new IntPtr(0); return; } } base.WndProc(ref m); }
That's it! You've now got a window, that WON'T MAXIMIZE.
If you want a window, that can ONLY be maximized or minimized (as in there's no WindowState.Normal), you will follow the same approach. But you'll find that in an article I wrote on codeproject.com a while ago. If you want all the details, just read them here: http://www.codeproject.com/useritems/DisableNormalWindowState.asp