A Couple of Quick Routines
by Erron Criddle - Techrron Holdings
Introduction Comment by Stephan Grieger:
I have been using these routines in my apps and I haven't come across any problems as yet.
The code to use to take care of form enabling/disabling is:
1) Declare a global integer variable and array:
Global ngForms% Global agForms(30) As Form2) On each form load event, call the following routine:
Sub sbrFormLoad (frm As Form)
On Error GoTo 0
' This routine disables a form via the load routine...
' It also updates the agForms array...
Call sbrResize(frm)
ngForms = ngForms + 1
Set agForms(ngForms) = frm
If ngForms > 0 Then agForms(ngForms - 1).Enabled = 0
End Sub
3) In each form unload, call the following routine:
Sub sbrFormUnload ()
On Error GoTo 0
' This routine simply enables a form via the unload routine...
Set agForms(ngForms) = Nothing
ngForms = ngForms - 1
If ngForms > = 0 Then agForms(ngForms).Enabled = -1
End Sub
Global sgWidth!
Global sgHeight!
sgWidth = Screen.Width / Screen.TwipsPerPixelX
sgHeight = Screen.Height / Screen.TwipsPerPixelY
Sub sbrResize(frm as Form)
' Resize the controls...
For I = 0 To frm.Controls.Count - 1
' Adjust the height,width,top,left & font size...
If TypeOf frm.Controls(I) Is CommonDialog Then
ElseIf TypeOf frm.Controls(I) Is dsSocket Then
ElseIf TypeOf frm.Controls(I) Is Timer Then
ElseIf TypeOf frm.Controls(I) Is Line Then
frm.Controls(I).X1 = frm.Controls(I).X1 * sgWidth / 800
frm.Controls(I).X2 = frm.Controls(I).X2 * sgWidth / 800
frm.Controls(I).Y1 = frm.Controls(I).Y1 * sgHeight / 600
frm.Controls(I).Y2 = frm.Controls(I).Y2 * sgHeight / 600
Else
frm.Controls(I).Width = frm.Controls(I).Width * sgWidth / 800
frm.Controls(I).Height = frm.Controls(I).Height * sgHeight / 600
frm.Controls(I).Top = frm.Controls(I).Top * sgHeight / 600
frm.Controls(I).Left = frm.Controls(I).Left * sgWidth / 800
If TypeOf frm.Controls(I) Is TList Then
frm.Controls(I).FontSize = frm.Controls(I).FontSize * sgHeight / 600
ElseIf TypeOf frm.Controls(I) Is Mh3dGroup Then
frm.Controls(I).FontSize = frm.Controls(I).FontSize * sgHeight / 600
ElseIf TypeOf frm.Controls(I) Is Label Then
frm.Controls(I).FontSize = frm.Controls(I).FontSize * sgHeight / 600
ElseIf TypeOf frm.Controls(I) Is Mh3dList Then
frm.Controls(I).FontSize = frm.Controls(I).FontSize * sgHeight / 600
frm.Controls(I).TitleFontSize =frm.Controls(I).TitleFontSize * sgHeight / 600
ElseIf TypeOf frm.Controls(I) Is TextBox Then
frm.Controls(I).FontSize = frm.Controls(I).FontSize * sgHeight / 600
ElseIf TypeOf frm.Controls(I) Is Mh3dText Then
frm.Controls(I).FontSize = frm.Controls(I).FontSize * sgHeight / 600
ElseIf TypeOf frm.Controls(I) Is Mh3dFrame Then
frm.Controls(I).FontSize = frm.Controls(I).FontSize * sgHeight / 600
ElseIf TypeOf frm.Controls(I) Is SSCommand Then
frm.Controls(I).FontSize = frm.Controls(I).FontSize * sgHeight / 600
ElseIf TypeOf frm.Controls(I) Is SSPanel Then
frm.Controls(I).FontSize = frm.Controls(I).FontSize * sgHeight / 600
End If
End If
Next I
End Sub
Other controls can be added of course.
PS: Please modify as you wish.