by K. Madhusudhana Rao (2 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 9th November 2001
Date Added: Mon 8th February 2021
Rating:
(1 Votes)
This code relates to *** Centering Form *** and Resize Form of Screen
API Declarations
Private lngFormHeight As Long
Private Sub Form_Load()
Dim Ctl As Control
'Store form dimensions in variables
lngFormWidth = ScaleWidth
lngFormHeight = ScaleHeight
'Store initial control dimensions
'in the Tag property - with error
'handling for those controls which
'do not have properties such as Top
'(eg, Line control)
On Error Resume Next
For Each Ctl In Me
Ctl.Tag = Ctl.Left & " " & Ctl.Top & " " & _
Ctl.Width & " " & Ctl.Height & " "
Ctl.Tag = Ctl.Tag & Ctl.FontSize & " "
Next Ctl
On Error GoTo 0
'give u r form name instead of frmlogin
frmLogin.Top = (Screen.Height - frmLogin.Height) / 2
frmLogin.Left = (Screen.Width - frmLogin.Width) / 2
End Sub
Private Sub cmdCancel_Click()
'set the global var to false
'to denote a failed login
LoginSucceeded = False
Me.Hide
End Sub
'this is code is resize of the form
Private Sub Form_Resize()
Dim D(4) As Double
Dim i As Long
Dim TempPoz As Long
Dim StartPoz As Long
Dim Ctl As Control
Dim TempVisible As Boolean
Dim ScaleX As Double
Dim ScaleY As Double
'Calculate the scale
ScaleX = ScaleWidth / lngFormWidth
ScaleY = ScaleHeight / lngFormHeight
On Error Resume Next
'Cycle through each control
For Each Ctl In Me
TempVisible = Ctl.Visible
Ctl.Visible = False
StartPoz = 1
'Read data from the Tag property
For i = 0 To 4
TempPoz = InStr(StartPoz, Ctl.Tag, " ", _
vbTextCompare)
If TempPoz > 0 Then
D(i) = Mid(Ctl.Tag, StartPoz, _
TempPoz - StartPoz)
StartPoz = TempPoz + 1
Else
D(i) = 0
End If
'Move the control based on data
'in the Tag property and the form
'scale...
Ctl.Move D(0) * ScaleX, D(1) * ScaleY, _
D(2) * ScaleX, D(3) * ScaleY
Ctl.Width = D(2) * ScaleX
Ctl.Height = D(3) * ScaleY
'Change font size
If ScaleX < ScaleY Then
Ctl.FontSize = D(4) * ScaleX
Else
Ctl.FontSize = D(4) * ScaleY
End If
Next i
Ctl.Visible = TempVisible
Next Ctl
On Error GoTo 0
End Sub
No comments have been posted about This code relates to *** Centering Form *** and Resize Form of Screen. Why not be the first to post a comment about This code relates to *** Centering Form *** and Resize Form of Screen.