Screen Resolution - Detect Change In

Toby Twerl

Newcomer
Joined
Apr 14, 2010
Messages
3
My application is designed such that it will handle screen resolutions of between 1024 x 768 and 1280 x 1024 at start up.

Problem is - If, whilst the app is running, the user changes the resolution coursing the forms to resize.

This is not too bad when switching from a low to a higher mode - at least you can still see the whole form, albeit not quite as you'd like.

However, when the reverse is true everything enlarges of course and you can't see the whole form.

Because of this there is no way to continue - short of the "Three Finger Salute".

My question is - Is there a way in VB.Net to monitor the screen resolution and raise a message if and when it changes and, if so, what measures can be taken to correct things?
 
easiest way is to add a handler to the Microsoft.Win32.SystemEvents.DisplaySettingsChanged event when either the application is run or when th e form is displayed.
 
Many thanks Plausibly,

Your suggestion led me to several solutions, the simplest of which seems to be the following:

Private Const WM_DISPLAYCHANGE As Integer = 126

Protected Overloads Overrides Sub WndProc(ByRef m As Message)
Select Case m.Msg
Case WM_DISPLAYCHANGE
FormRawMaterial.Size = Me.ClientSize
FormRawMaterial.Show()
MessageBox.Show("Screen resolution has changed")
Exit Select
End Select
MyBase.WndProc(m)
End Sub

This works great and does indeed notify the application that the screen resolution has changed - again, thank you.

At this point I have two options:
1) The easy one - that is, to notify the user that because the resolution has changed the application must terminate.
2) The one that stumps me and the one I would like is to correct the display to reflect this change.

My application consists of a main form that is displayed maximized when the application starts and as such fills the whole screen - regardless of resolution.

This main form, in turn, hosts several "sub" forms - sized to fit on the screen at its lowest resolution and centered on the main form.

These sub forms therefore appear large at at low res and small at high res which is not a problem.

For what it may be worth the sub forms are declared as controls residing on the main form and are shown and hidden as required.

Can anyone direct me further along the path?
Should I me investigating an Application Settings file?
 
Back
Top