views:

155

answers:

4

Hi! Iam looking for some hint or solution regarding following problem.

I have a .NET 2.0 WinForm dialog which operates in Dual Screen environment. The Working area is set by .NET Framework to reflect the Primary screen. I want to MAXIMIZE Form to BOTH screens but after clicking the "maximize button", dialog is maximized only to "active" screen (active I mean screen on which dialog is currently placed).

Iam not interested in bounds solution, this works, but when clicked Maximize button it forces the dialog back to one of 2 screens.

I would be gratefull for any help or hints.

A: 

Do not do it.

Here we go: the behavior is as defined BY THE USER and the operating system. You should not override user wishes.

Bonding of screens (to form one virtual screen) is possible with some hardware drivers (ATI comes to my mind for current cards, they call it EyeFinity).

While I see the sense of it - in MOST cases it breaks user expectations of how the program would behave. And I say that as someone working with 3+ screens often ;) As in: using one program across all screens ;) I would NOT want that ;)

TomTom
The USER have requested such feature! That's why Iam seeking solution for it!
jodie
The problem with this sort of advice is that you just don't have enough context to know if it's appropriate. There are lots of situations where application authors need lots of control over complete systems - they're not the desktop/office applications you seem to be thinking of, but things like kiosks and industrial control.
Will Dean
The problem is tha this is not even simple to answer IF needed - which is also ONE reason MS did not include it. Two screens? CAN you 100% assume both are "side by side" and have the same size / resolution? If not - things get REALLY ugly. Industrial Control can work with EITHER using ATI Eyefinity / Nvidia equivalent to make multiple screens appear as one for the OS (so the problem does not exist) or the user making the window large manually (which is what my current main contractor does on a 4 LARGE screens control wall).
TomTom
+1  A: 

Combine the 2 screen sizes and set your form to that resolution. Something like:

int height = 0;
int width = 0;
foreach (screen in System.Windows.Forms.Screen.AllScreens)
{
  //take smallest height
  height = (screen.Bounds.Height <= height) ? screen.Bounds.Height: height;
  width += screen.Bounds.Width;
}

Form1.Size = new System.Drawing.Size(width, height);

To override the maximize button you can check via WndProc for the maximize event

const int WM_SYSCOMMAND= 0x0112;
const int SC_MAXIMIZE= 0xF030;
protected override void WndProc(ref Message m)
{
    if(m.Msg==WM_SYSCOMMAND)
    {
        if((int)m.WParam==SC_MAXIMIZE)
        {
            MessageBox.Show("Maximized!!");
            return;
        }
    }
    base.WndProc (ref m);
}

or register to the Resize event of the form (you should check if it's resize or an maximize) (MSDN)

PoweRoy
yep ... just what I was going to say...My scenario goes like this:1. User clicks MAXIMIZE2. Form is maximized to BOTH screens Please observe that MAXIMIZE operations causes several things except changing size:1) FIXED position (cant move)2) FIXED size (cant resize)3) Maximize button responds to "rollback to last size" actionAs I can simulate 1) and 2) I don't know how to simulate 3) (Maximize button is allowing to revert to last size) etc..
jodie
Thx for WinAPI code - I will test it ASAP
jodie
Also, as far as I can see, it looks wrong. If you have two screens that are 640x480, you will end up with a form with the size 1280x960. Should have been 1280x480 or 640x960 depending on how the screens are set up.
Svish
I assume that primary screen is smaller or equal so maximize show smaller window on the bigger (second screen). For now I assume that user have two screens with same res
jodie
fixed height (width is only interesting). If you have two screen with 2 different resolutions then maximizing over 2 screens is going to be a problem.
PoweRoy
A: 

Get the users to change their Windows display settings (or change it for them).

For instance, on NVidia cards, the default Windows behaviour is called 'Dualview'. If you enable 'Horizontal span', then maximized windows will start behaving as you describe.

Tim Robinson
Iam looking for universal solution which is not card specific... Some applications (closed source) work as I describe, but I cant find principle how they do it...
jodie
There isn't a universal solution. Windows itself maximizes windows to fill one monitor. Card vendors achieve this by making two physical monitors appear as one big one.
Tim Robinson
A: 

Only solution I know is using the bounds in combination with overriding the Resize event. In the handler you can check the WindowState property to see if the form is Maximized or Minimized. If maximized, resize the window again with all screen bounds together.

I do see a problem with what you want.
What if the second screen is smaller then the first (visa versa)...
What if the second screen is located diagonal (e.g. top left) of the first screen (visa versa)...
There will be parts that won't be visible!

jerone
I assume for now that they are equal size. Iam considering to run your solution, but It would be great If I know how to force MAXIMIZE button to display other glyph
jodie