views:

65

answers:

2

My customer want me to change the default maximise-buttons functionality to maximise the form over all screens the customer have. I have already written some code to measure the correct rectangle to put the form to, but when i assign it to the MaximisedBounds attribute of the form, there are some issures: The screen (in my 2 screen tests) that the form was not on before the click get only one paint, ans if you click on the form on the other screen it is like you have clicked "under" it onto the next window beneath.

Of course there are other ways to solve this problem (like in http://stackoverflow.com/questions/1295999/event-when-a-window-gets-maximized-un-maximized), i wounder if the described behaviour is a bug, or my mistake. Is there anything to do before changing the MaximisedBounds attribute to make it work?

A: 

I've been able to make forms fill the 2 whole screens by setting the Size property directly, rather than the MaximisedBounds value.

Matt Warren
yes, i also considered this as valid option (and it is my current solution for the problem), but is it also good coding style? I wonder how to use MaximisedBounds correctly.
Stimpatch
A: 

I'd agree with Matt. Setting the "MaximizedBounds" is not a good idea. As written in http://stackoverflow.com/questions/1295999/event-when-a-window-gets-maximized-un-maximized, I would override the WndProc-method. There you can handle the different received commands from your window on your own.

The main thing to do is to write your own code for the "SC_MAXIMIZE"-windowcommand (as written in the referenced article above). There you can manually set the form's size e.g. In this case the form won't be really maximized. Actually is it still in normal WindowState. To prevent the user from changing this state you need to "catch" some other windowcommands.

The overridden WndProc method could be like this:

    protected override void WndProc(ref Message m)
    {
        if(m.Msg == 0x0112) // WM_SYSCOMMAND
        {
            if(m.WParam == new IntPtr(0xF012)) //TITLE_CLICK_ONCE
            {
                // catch, this command can occur, when form starts to move
            }

            if(m.WParam == new IntPtr(0xF001) // RESIZE_ON_EDGE
            || m.WParam == new IntPtr(0xF002)
            || m.WParam == new IntPtr(0xF003)
            || m.WParam == new IntPtr(0xF004)
            || m.WParam == new IntPtr(0xF005)
            || m.WParam == new IntPtr(0xF006)
            || m.WParam == new IntPtr(0xF007)
            || m.WParam == new IntPtr(0xF008))
            {
                // catch the resizing
            }

            if(m.WParam == new IntPtr(0xF032)) // SECOND_CLICK_ON_TITLEBAR
            {
                // catch. causes a maximization (or resuming to normal window-mode)
            }

            if(m.WParam == new IntPtr(0xF030)) //SC_MAXIMIZE
            {
                // the actual point, where to enter your code
                // this command occurs, when the "Maximize"-button is pressed
            }
        }

        // maybe abort calling of the base-method at specified window-commands,
        // when you want to make your own code by simply "return;"
        base.WndProc(ref m);
    }
Jericho
Gk, guess this is the way to go then.
Stimpatch