Click here to Skip to main content
11,812,712 members (73,119 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# Win7 screen
Anyone else have this problem and/or a work-around?

I would like my application to be nicely sized and centered so I have code like this:
int border = 50;
System.Drawing.Rectangle rr = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
if (Width > rr.Width - border)
    Width = rr.Width - border;
if (Height > rr.Height - border)
    Height = rr.Height - border;
Left =  (rr.Width - ActualWidth) / 2;
Top = (rr.Height - ActualHeight) / 2;;
and this works properly when the Windows 7 font size is set to 100%. The screen resolution is 1920x1080.

When I go (in Windows 7) to "Make text and other items larger or smaller" and set the size to medium (125%), things break. 'rr' still shows 1920x1080 and the application hangs off the edge of the screen. If I maximize the application, it reports an ActualWidth, ActualHieght of only 1550x840 (which is, oddly enough, about 1920x1080 / 125%).

It seems that Windows makes everything bigger by making the pixels bigger but doesn't understand that that means there will be fewer pixels on the screen. How do I get Windows to tell me how big the scren really is, not how big it might have been? Or where can I find that 125% size setting so I can do the division myself?
Posted 15-Apr-12 17:34pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Thanks for your answer, it led me to the actual answer...

Since I'm in WPF, there are properties in SystemParameters which seem to work.

Rect rr = new Rect() { Width = SystemParameters.PrimaryScreenWidth, Height = SystemParameters.PrimaryScreenHeight };
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

There are some properties to look at: AutoSize, AutoSizeMode, AutoScaleMode. But they do interfere with each other...

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

  Print Answers RSS
0 Abhinav S 205
1 CHill60 180
2 KrunalRohit 169
3 Palash Mondal_ 140
0 OriginalGriff 3,877
1 KrunalRohit 2,496
2 CPallini 2,240
3 Maciej Los 2,205
4 ppolymorphe 1,750

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 16 Apr 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100