I need to find out if the user’s screen is set to normal 96 dpi (small size), large 120 dpi fonts, or something else. How do I do that in VB.NET (preferred) or C#?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The best way is just to let the form resize itself automatically, based on the user’s current DPI settings. To make it do that, just set the
AutoScaleModeproperty toAutoScaleMode.Dpiand enable theAutoSizeproperty. You can do this either from the Properties Window in the designer or though code:Or, if you need to know this information while drawing (such as in the
Paintevent handler method), you can extract the information from theDpiXandDpiYproperties of theGraphicsclass instance.Finally, if you need to determine the DPI level on-the-fly, you will have to create a temporary instance of the
Graphicsclass for your form, and check theDpiXandDpiYproperties, as shown above. TheCreateGraphicsmethod of the form class makes this very easy to do; just ensure that you wrap the creation of this object in aUsingstatement to avoid memory leaks. Sample code: