Visual Basic Concepts
SysInfo Scenario 2: Adjust to Changes in Screen Size and Resolution
Using a few of the operating system properties and events provided by the SysInfo control, you can detect and respond to changes in screen size and resolution.
The following example tests the size of the active form after a change in screen resolution and adjusts the size of the form if it exceeds the visible screen area.
To resize a form after screen resolution changes, use the DisplayChanged event with the WorkAreaWidth, WorkAreaLeft, and WorkAreaTop properties.
To resize a form after screen resolution changes
Create a new project in Visual Basic.
Add a SysInfo control to the form.
Add the following code to the SysInfo control’s DisplayChanged event procedure:
Private Sub sysDetectOS_DisplayChanged() If Screen.ActiveForm.Width > _ sysDetectOS.WorkAreaWidth Then Screen.ActiveForm.Left = _ sysDetectOS.WorkAreaLeft Screen.ActiveForm.Width = _ sysDetectOS.WorkAreaWidth End If If Screen.ActiveForm.Height > _ sysDetectOS.WorkAreaHeight Then Screen.ActiveForm.Top = _ sysDetectOS.WorkAreaTop Screen.ActiveForm.Height = _ sysDetectOS.WorkAreaHeight End If End Sub