SysInfo Scenario 2: Adjust to Changes in Screen Size and Resolution

See Also

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

  1. Create a new project in Visual Basic.

  2. Add a SysInfo control to the form.

  3. 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