Following is a subroutine that will set the video resolution for multiple forms.
Load Form
Call SetDeviceIndependentWindow(Form)
Form.Show
The subroutine was in a different module and this has always worked for me but I also have never tried to call it from the Form Load Event.
As a side note, I had to make a change in the subroutine in order for it work with my machine. The subroutine relies on the fact that Screen.TwipsPerPixelX, Screen.TwipsPerPixelY will change according to whatever video resolution is selected. My problem may be due to the fact that the video drivers for the Cirrus Logic video chip have been written poorly but on my system irregardless of what video resolution I was in 640 x 480, 800 x 600, etc. the value for Screen.TwipsPerPixelX or Y never changed from 12 but I have worked on other machines with different video cards and the value did change. I have included a modified version of the routine.
Sub SetDeviceIndependentWindow (TheForm As Form)
Dim DesignX%
Dim DesignY%
Dim XFactor As Single
Dim YFactor As Single
Dim Z As Integer
' DesignX% = 12
' DesignY% = 12
' XFactor = DesignX% / Screen.TwipsPerPixelX
' YFactor = DesignY% / Screen.TwipsPerPixelY
'** This is what I changed, I design my screens to look appropriate for VGA and then resize the screen if the user is using a higher video resolution
XFactor = Screen.Width / 9600
YFactor = Screen.Height / 7200
If XFactor = 1 And YFactor = 1 Then
Exit Sub
End If
TheForm.Move TheForm.Left * XFactor, TheForm.Top * YFactor,
TheForm.Width * XFactor, TheForm.Height * YFactor
For Z = 0 To TheForm.Controls.Count - 1
'If TypeOf TheForm.Controls(Z) Is CommonDialog Then
If TypeOf TheForm.Controls(Z) Is Timer Then
ElseIf TypeOf TheForm.Controls(Z) Is Menu Then
ElseIf TypeOf TheForm.Controls(Z) Is Line Then
ElseIf TypeOf TheForm.Controls(Z) Is DriveListBox Then
TheForm.Controls(Z).Move TheForm.Controls(Z).Left * XFactor, TheForm.Controls(Z).Top, TheForm.Controls(Z).Width * YFactor
ElseIf TypeOf TheForm.Controls(Z) Is ComboBox Then
If TheForm.Controls(Z).Style <> 1 Then
TheForm.Controls(Z).Move TheForm.Controls(Z).Left * XFactor, TheForm.Controls(Z).Top * YFactor, TheForm.Controls(Z).Width * XFactor
End If
Else
TheForm.Controls(Z).Move TheForm.Controls(Z).Left * XFactor, TheForm.Controls(Z).Top * YFactor, TheForm.Controls(Z).Width * XFactor, TheForm.Controls(Z).Height * YFactor
If TypeOf TheForm.Controls(Z) Is TextBox Then
TheForm.Controls(Z).FontSize = TheForm.Controls(Z).FontSize * XFactor
ElseIf TypeOf TheForm.Controls(Z) Is Label Then
TheForm.Controls(Z).FontSize = TheForm.Controls(Z).FontSize * XFactor
End If
End If
Next Z
End Sub
|