-
If I build my project in a computer with display screen setting 640*480 .When I use this project in different display setting (800*600) the forms don't fit to Screen.It's small than screen.How can I auto resize forms to fit to Screen when the Display Setting(In control panel ) was changed.
-
You may have to change one or two things, and define some of the global variables it uses, but I think the following should work for you:
Code:
Public Sub SetWindowSize(FormName As Form)
'***************************************************************************
'Purpose: Changes position and size of controls and forms to create a
' device-independent form
'Inputs: FormName - Name of the form to be resized
'Outputs: None
'***************************************************************************
Dim nX As Integer 'Loop variable
Dim nXTwips As Integer 'Vertical screen twips
Dim nYTwips As Integer 'Horizontal screen twips
Dim nXPixels As Integer 'Vertical Pixels
Dim nYPixels As Integer 'Horizontal Pixels
nXTwips = Screen.TwipsPerPixelX
nYTwips = Screen.TwipsPerPixelY
nYPixels = Screen.Height / nYTwips
nXPixels = Screen.Width / nXTwips
On Error Resume Next 'Menu objects and perhaps others don't support Move method
'Calculate the ratio of the current screen size to the size of
'the design screen (Designed in 640 x 480)
gfXFactor = nXPixels / 640
gfYFactor = nYPixels / 480
'The calculation of vsbDetailScrollBar.Max in frmDetails Form Load
'fails if the result is > frmpreview.vsbpreview.max. It can get that large if the factor is too large.
If gfXFactor > 1.25 Then gfXFactor = 1.25
If gfYFactor > 1.25 Then gfYFactor = 1.25
'If running on the same type of system as when designed, avoid the rest.
If gfXFactor = 1 And gfYFactor = 1 Then
frmMain.mnuNormalScreens.Enabled = False
frmMain.mnuLargeScreens.Enabled = False
Exit Sub
End If
'Adjust form so that it is in the same relative location and is
'proportionally the same size on the current system as it is on
'the design system
FormName.Move FormName.Left * gfXFactor, FormName.Top * gfYFactor, _
FormName.Width * gfXFactor, FormName.Height * gfYFactor
'Modify each control on the form so it is proportionally spaced
'and sized
For nX = 0 To FormName.Controls.Count - 1
'Some controls need special treatment
If TypeOf FormName.Controls(nX) Is DriveListBox Then
FormName.Controls(nX).Move _
FormName.Controls(nX).Left * gfXFactor, _
FormName.Controls(nX).Top, _
FormName.Controls(nX).Width * gfXFactor
ElseIf TypeOf FormName.Controls(nX) Is ComboBox Then
FormName.Controls(nX).Font.Size = _
FormName.Controls(nX).Font.Size * gfXFactor
If FormName.Controls(nX).Style <> 1 Then 'Not a simple Combo Box
FormName.Controls(nX).Move _
FormName.Controls(nX).Left * gfXFactor, _
FormName.Controls(nX).Top * gfYFactor, _
FormName.Controls(nX).Width * gfXFactor
End If
ElseIf TypeOf FormName.Controls(nX) Is Grid Then
FormName.Controls(nX).RowHeight(0) = _
FormName.Controls(nX).RowHeight(0) * gfYFactor
FormName.Controls(nX).Font.Size = _
FormName.Controls(nX).Font.Size * gfXFactor
FormName.Controls(nX).Height = _
FormName.Controls(nX).Height * gfXFactor
Else 'Move and size all other controls
FormName.Controls(nX).Move _
FormName.Controls(nX).Left * gfXFactor, _
FormName.Controls(nX).Top * gfYFactor, _
FormName.Controls(nX).Width * gfXFactor, _
FormName.Controls(nX).Height * gfYFactor
'Adjust the font size of controls
If TypeOf FormName.Controls(nX) Is TextBox _
Or TypeOf FormName.Controls(nX) Is Label _
Or TypeOf FormName.Controls(nX) Is CheckBox _
Or TypeOf FormName.Controls(nX) Is Frame _
Or TypeOf FormName.Controls(nX) Is CommandButton _
Or TypeOf FormName.Controls(nX) Is OptionButton _
Or TypeOf FormName.Controls(nX) Is PictureBox _
Or TypeOf FormName.Controls(nX) Is ListBox Then
FormName.Controls(nX).Font.Size = _
FormName.Controls(nX).Font.Size * gfXFactor
End If
End If
Next
End Sub
------------------
Marty
-
If the problem is Screen Resolution Changes use this . . .
if u want a form to always be in the center of a screen , with any screen resolution add thsi to form load even procudure:
Me.Height = Screen.Height / 2
Me.Width = Screen.Width / 2
Me.Top = (Screen.Height / 2) - (Me.Height) / _ 2
Me.Left = (Screen.Width / 2) - (Me.Left) / 2
------------------
Cory Sanchez