5

Problem description:

I am currently developing a Visual Basic .NET application. It turns out that my application does not get displayed properly on systems that run on a different dpi-setting than "standard" (100% = 96dpi under windows xp).

When I change the system's dpi settings my GUI looks slightly messed up as you can see in the following screenshots (since this is a scaling issue it should not matter that the text on the screenshots is in German; sorry for this):

Windows XP, 100% scale, 96 dpi -> Everything looks like I expect it to. Windows XP, 100% scale, 96 dpi

Windows XP, 125% scale, 120 dpi -> The buttons at the bottom of the window do no longer fit inside the window. Windows XP, 125% scale, 120 dpi

What I want to achieve:

In case the display scale is set to anything else than 100% I would like to show the user a warning dialog box as soon as the application starts.

Question:

Is there any possibility to read the system's dpi value? If so, how would that be? There seems to be a DisplayProperties-class as well as DisplayInformation-class, but as far as I can see it is only available for Windows-Store-Apps.

Christian
  • 1,589
  • 1
  • 18
  • 36
  • 2
    Solution: use WPF, which is resolution independent by default. winforms doesn't support anything. – Federico Berasategui Jan 16 '14 at 15:31
  • @HighCore is correct. This is one of the reasons WPF was created in the first place – Zache Jan 16 '14 at 15:33
  • Thanks guys, I'll have a look at WPF and consider it for the next update. – Christian Jan 17 '14 at 06:02
  • 1
    I cannot resist to add some (unasked and completely off-topic) UI advice: One exclamation mark is enough (you want your application to appear professional, not juvenile), text should be centered in the button, the big space before "JETZT" looks like a display bug, button captions should begin with a capital letter (compare to the XP dialogs on the left side of your screen shot). – Heinzi Jan 17 '14 at 06:21
  • Thank you for your feedback Heinzi. I edited the picture by intention in order nor to post "advertisement" here. Usually the product name appears where you see the blank spaces above. For clarification I should have used black boxes. Also, the blue image box contains a product specific image. Thus, in the application itself the text is centered on the buttons. However, you are right regarding the exlamation marks! I'll think about that with the next update. – Christian Jan 17 '14 at 09:54
  • For clarification I added black boxes to where I masked the application name. – Christian Jan 17 '14 at 10:09

1 Answers1

6

The DpiX and DpiY properties of the Graphics class contain this information:

Using g = Me.CreateGraphics()
    Dim dpiX = g.DpiX
    Dim dpiY = g.DpiY
End Using

Since you are using Windows Forms, you can create a Graphics object with Form.CreateGraphics.


Of course, the best course of action would be to make your application look great on any DPI setting. If you cannot move to WPF, the following SO question contains a lot of hints on how to make this work with WinForms:

Community
  • 1
  • 1
Heinzi
  • 167,459
  • 57
  • 363
  • 519