Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Span program across multple monitors

Status
Not open for further replies.

robertfah

Programmer
Mar 20, 2006
380
US
Hi all,

I've got 2, 20" monitors running 1280x1024 that I develop on. I've written a program that I want to span both monitors when maximized, is there a way to do this? I tried to set the width to 2560, but it doesn't seem to work.

Any ideas would be greatly appreciated.
 
Ok, I think I found some help, which is my code below:
Code:
namespace BSOD
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (Screen.AllScreens.Length > 1)
            {
                Form1 frm = new Form1();
                frm.StartPosition = FormStartPosition.Manual;
                Screen screen = GetSecondaryScreen();

                frm.Location = screen.WorkingArea.Location;
                frm.Size = new Size(screen.WorkingArea.Width, screen.WorkingArea.Height);
                frm.Show();
            }
        }

        public Screen GetSecondaryScreen()
        {
            if (Screen.AllScreens.Length == 1)
                return null;

            foreach (Screen screen in Screen.AllScreens)
                if (screen.Primary == false)
                    return screen;

            return null;
        }
    }
}

But now I get an error that says "Error creating window handle". When running it through the debugger, the code is looping indefinately......anyone know why?
 
The reason that Windows doesn't maximise apps to the whole desktop (i.e. all monitors) is because you might have monitors with different resolutions. I have this at home, a 1680 x 1050 main monitor and a 900 x 1440 secondary one (i.e. a wide-screen in portrait mode). Maximising an app to both of those wouldn't make any sense.

If you want you app to work on all multi-monitor set-ups you need to display it as a normal (non-maximised) window and set its dimensions accordingly, whilst taking account of the facts that a) the user may have more than two monitors and b) they may not be side-by-side!

Alternatively there's a really handy multi-monitor tool that I use called UltraMon. Amongst its features is an option to add a control to every window that maximises it to your desktop.

Regards

Nelviticus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top