Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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:
C#
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

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.

C#
Rect rr = new Rect() { Width = SystemParameters.PrimaryScreenWidth, Height = SystemParameters.PrimaryScreenHeight };
 
Share this answer
 
There are some properties to look at: AutoSize, AutoSizeMode, AutoScaleMode. But they do interfere with each other...
 
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