Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi all,

Has anyone ever looked at programmatically recreating the monitor layout as shown by the Display Settings dialog box in Windows? I'm talking about the screen that shows all your monitors, and how they're positioned relative to each other. On Windows 10, you get there by right-clicking on the desktop and selecting Display Settings. On Windows 7, you right-click on the desktop and select Screen Resolution.

People can have complex layouts nowadays, and knowing what configuration they use can come in handy in some cases. While it's trivial to get all the *values* that describe the layout by iterating over System.Windows.Forms.Screens.AllScreens (specifically, Screen.Bounds), visualizing those numbers can get rather difficult, especially when you have more than 2 monitors, and you throw in negative coordinates on top of that.

My question: Has anyone ever tried to use those values to render an Image from them? Obviously I wouldn't want something that's 1:1; a small-ish thumbnail is all I'm after. Bonus if it can display coordinates at each monitor's top-left/bottom-right corners and identify them by name (Screen.DeviceName), and perhaps even show what side of each monitor the taskbar is docked on (which can be inferred through Screen.Bounds vs Screen.WorkingArea).

All the data's there...I just don't have the patience to sit down with pen and paper and figure out exactly how to render all the elements using GDI, and then turn that into an Image (strictly speaking, I'm not even trying to render it to screen, I want to generate an Image so it can be saved to disk).

What I have tried:

It's all in System.Windows.Forms.Screens.AllScreens...I just don't know where to start to render all the rectangles, and turn the final results into an Image.
Posted
Updated 26-Jun-17 5:05am

Quote:
I just don't have the patience to sit down with pen and paper and figure out exactly how to render all the elements using GDI
Then I suspect that this app isn't going to happen: if you can't be bothered to do the work, why would you think we would want to do it for you?

If you want someone to write your code, you have to pay - I suggest you go to Freelancer.com and ask there.

But be aware: you get what you pay for. Pay peanuts, get monkeys.

The idea of "development" is as the word suggests: "The systematic use of scientific and technical knowledge to meet specific objectives or requirements." BusinessDictionary.com[^]
That's not the same thing as "have a quick google and give up if I can't find exactly the right code".
So either pay someone to do it, or learn how to write it yourself. We aren't here to do it for you.
 
Share this answer
 
This should hopefully get you started

static void Main(string[] args)
{
    // 120 x 120 thumbnail
    Bitmap image = new Bitmap(120, 120);

    Graphics g = Graphics.FromImage(image);
    g.Clear(Color.White);

    Pen p = new Pen(Color.Black, 3);

    // Primary display
    g.DrawLine(p, PrimaryDisplayEnabled(image), PrimaryDisplayDisabled(image));

    // Secondary display
    g.DrawLine(p, SecondaryDisplayEnabled(image), SecondaryDisplayDisabled(image));

    // Orientation
    g.DrawLine(p, OrientationLandscape(image), OrientationPortrait(image));

    // Resolution
    g.DrawEllipse(p, Resolution(image));

    image.Save(@"c:\temp\test.png", System.Drawing.Imaging.ImageFormat.Png);
}

private static Point PrimaryDisplayEnabled(Bitmap image)
{
    return new Point(image.Width - 110, image.Height - 110);
}

private static Point PrimaryDisplayDisabled(Bitmap image)
{
    return new Point(image.Width - 110, image.Height - 20);
}

private static Point SecondaryDisplayEnabled(Bitmap image)
{
    return new Point(image.Width - 110, image.Height - 110);
}

private static Point SecondaryDisplayDisabled(Bitmap image)
{
    return new Point((image.Width / 12) * 5 , image.Height - 20);
}

private static Point OrientationLandscape(Bitmap image)
{
    return new Point((image.Width / 12) * 5, (image.Width / 12) * 10);
}

private static Point OrientationPortrait(Bitmap image)
{
    return new Point((int)(image.Width * 1.5) - (image.Height + 10), 10);
}

private static Rectangle Resolution(Bitmap image)
{
    return new Rectangle((image.Width / 2) + 5, 10, image.Height / 3, 90);
}
 
Share this answer
 
v2
Comments
dandy72 26-Jun-17 12:32pm    
That should go a long way to get me started, thanks for that. I read the Petzold books decades ago and remember the chapters on this sort of thing, and it turns out custom drawing with the GDI primitives is something I was fortunate enough (?) to avoid for this long. I just need to sit down one evening and figure out the math. That's what I was trying to avoid--maybe, just maybe, someone's already done this and published what probably amounts to one function. It can't be hard, you just have to work through it once. It's not a homework :-) it's just not a priority enough for me to try from scratch without asking first.

I appreciate the response, it'll definitely be useful. Once I find the time to work it out, I'll be happy to share the results here.
dandy72 1-Jul-17 13:17pm    
Just found a bit of time to try it out...

While I recognize the humor, this has been more helpful than you'd probably think. It's still exactly what I needed to get started.
F-ES Sitecore 3-Jul-17 4:07am    
Glad you at least saw the joke :D I actually felt quite bad when you posted your initial comment :)
dandy72 3-Jul-17 8:09am    
Nah, it's all good. As I wrote, it turns out all I needed was a trivial example to get the ball rolling, and yours did exactly that.

As it stands, the code is now written and looks *great* (at least I think so) - but what I still need to test is what happens when working with negative coordinates, which I know needs to be considered. Right now something would probably crash, or at least render, very badly.
Quote:
My question: Has anyone ever tried to use those values to render an Image from them? Obviously I wouldn't want something that's 1:1; a small-ish thumbnail is all I'm after. Bonus if it can display coordinates at each monitor's top-left/bottom-right corners and identify them by name (Screen.DeviceName), and perhaps even show what side of each monitor the taskbar is docked on (which can be inferred through Screen.Bounds vs Screen.WorkingArea).

This suspiciously appears to be a thinly veiled request for other people to hand over their work so you don't have to do it yourself. What do you think the answer to that question is going to be?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900