VB3 Adjust Form Size for Different Video Screen ResolutionsID: Q103646
|
Different display devices can have different resolutions (twips per pixel
ratios). These differences can cause form and control sizes and locations
to appear differently than when they were created. Two solutions to this
problem are:
Dim FontHeight%, FontWidth%
FontWidth% = TextWidth ( "X" )
FontHeight% = TextHeight( "Xg" )
Sub Form1_Resize()
If InResize% <> -1 Then
InResize% = -1
' Sample code which would trigger a resize event
form1.Width = frmWidth%
form1.Height = frmHeight%
InResize% = 0
End If
End Sub
form1.Top = 0
form1.left = 0
form1.Width = 100
form1.Height = 100
as opposed to this code which triggers only one resize event:
Dim bTop%, bLeft%, bWidth%, bHeight%
bTop% = 0
bleft% = 0
bWidth% = 100
bHeight% = 100
form1.move bLeft%, bTop%, bWidth%, bHeight%
Sub Form_Load ()
' Set up a picture box:
Picture1.AutoSize = True
Picture1.Move 0, 0
' Set up the labels and command button:
Xtwips& = Screen.TwipsPerPixelX
Ytwips& = Screen.TwipsPerPixelY
Ypixels& = Screen.Height / Ytwips&
Xpixels& = Screen.Width / Xtwips&
label1.Caption = "Below is resolution that you are running in"
label2.Caption = Str$(Xpixels&) + " by " + Str$(Ypixels&)
label1.Width = Picture1.Width
label2.Width = Picture1.Width
label1.Left = 0
label2.Left = 0
label1.Top = Picture1.Height + 10
label2.Top = label1.Top + label1.Height + 10
command1.Top = label2.Top + label2.Height + 10
command1.Left = (Picture1.Width - command1.Width) / 2
' Size the form to fit the picture box, labels, and command button
ScaleMode = 1 ' twips
Width = Width - ScaleWidth + Picture1.Width
'VB3Line: Enter the following lines as one line
Height = Height - ScaleHeight + Picture1.Height + label1.Height _
+ label2.Height + command1.Height
End Sub
Sub Command1_Click ()
End
End Sub
Additional query words: 3.00
Keywords : kbcode kbWndw
Version : 3.00
Platform : WINDOWS
Issue type :
Last Reviewed: June 2, 1999