blog.SiteXero.net

 — posted on August 28th, 2009 with 1 comment

So earlier, I decided to work on Imaer again (see last post) due to the fact that I am now running a dual monitor setup and Imaer’s upload screen selection option would only build its selection form on the primary screen. I needed a way to make the form span all the screens perfectly.

I of course went to Google and searched for some information, but couldn’t find any examples doing exactly what I wanted. I found some useful information regarding the class I’m using though, which is System.Windows.Forms.Screen. I realized how incredibly simple it is to do what I wanted to do after taking a look at this class, and decided to post the small amount of code so that maybe someone in the future will be able to find it when they decide to Google it.

    int h = 0;
    int w = 0;
    int x = 0;
    int y = 0;

    foreach (Screen s in Screen.AllScreens)
    {
        if (s.Bounds.X < x)
            x = s.Bounds.X;
        if (s.Bounds.Y < y)
            y = s.Bounds.Y;
        h += s.Bounds.Height;
        w += s.Bounds.Width;
    }

    this.Height = h;
    this.Width = w;
    this.Left = x;
    this.Top = y;

That’s pretty much it. You will of course need to make sure you’re importing the System.Windows.Forms namespace first if you’re going to access the Screen class directly like that. Yes, this will even work fine when the user only has one monitor. It also doesn’t matter how their monitors are setup; whether the display 2 is to the left of display 1 or below it.

There’s one thing to note, however. This uses the full bounds of the screens, meaning not just the working space. This will only be a problem if you don’t have your form set to always on top because part of it will get cut off by the start menu or other fixed items like a sidebar perhaps.

Tags:

 

1 Comment

gempaoo@yisuesd.ru” rel=”nofollow”>1…

no more…

Leave a Comment

 
©2009 Nick S. - Layout designed by Matt S. - blog.SiteXero.net is proudly powered by WordPress - Subscribe to entries/comments
This page executed 16 queries in 0.182 seconds