VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Resizes forms depending on Screen Resolution. I had a typical problem in one of the projects. I dev

by Jayant J Sane (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 24th September 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Resizes forms depending on Screen Resolution. I had a typical problem in one of the projects. I developed entire project on my PC which is set

Rate Resizes forms depending on Screen Resolution. I had a typical problem in one of the projects. I dev



On Error Resume Next ' O'God..  Do not terminate in case of error,  Pardon Me..
Dim nI As Integer
Dim ctl As Object, frm As Object
Dim nW As Long, nH As Long
Dim nHRatio As Single, nWRatio As Single

' ------ First Determine which form is Active now..  ------
' ------ I normaly Disabel all forms other than Current form in my Projects. ------
For Each frm In Forms
       If frm.Enabled Then
           Set frm = frm.Name
           Exit For
       End If
Next

' ------ Following ratios are based on assumption that U R Desigining forms at 800 X 600 Resolution
nW = Screen.Width: nH = Screen.Height
nWRatio = nW / 12000: nHRatio = nH / 9000

If nWRatio = 1 Then
    ' ------ No need to resize form if Ration is Unity.
    frm.Left = 0: frm.Top = 0
    frm.WindowState = 2 ' Max. Size.
    GoTo EndResize
Else
    MsgBox  "Resizing Form to Suit to Screen Size.. " & vbNewLine & "Please Press Any Key.."
    frm.WindowState = vbNormal
End If

frm.Width = nW: frm.Height = nH
frm.Left = -50: frm.Top = -50

For nI = 0 To frm.Controls.Count - 1
    Debug.Print frm.Controls(nI).Left
    Debug.Print frm.Controls(nI).Name
    Set ctl = frm.Controls(nI)
    ' ------ Now Depending on control type, set its Top, left, Height and Width properties.

     ctl.Left = ctl.Left * nWRatio: ctl.Top = ctl.Top * nHRatio
     ctl.Width = ctl.Width * nWRatio: ctl.Height = ctl.Height * nHRatio

    If TypeOf ctl Is TextBox Or TypeOf ctl Is ComboBox Or TypeOf ctl Is Label or Typeof ctl is Frame
        ctl.FontSize = ctl.FontSize * nWRatio
    End If
    if TypeOf ctl Is CommandButton Then
        ctl.FontSize = ctl.FontSize * nWRatio
    End If
    If TypeOf ctl Is Line Then ' Graphic Controls..
        ctl.X1 = ctl.X1 * nWRatio: ctl.Y1 = ctl.Y1 * nHRatio
        ctl.X2 = ctl.X2 * nWRatio: ctl.Y2 = ctl.Y2 * nHRatio
    End If
Next

frm.Refresh
EndResize:
End Function



Download this snippet    Add to My Saved Code

Resizes forms depending on Screen Resolution. I had a typical problem in one of the projects. I dev Comments

No comments have been posted about Resizes forms depending on Screen Resolution. I had a typical problem in one of the projects. I dev. Why not be the first to post a comment about Resizes forms depending on Screen Resolution. I had a typical problem in one of the projects. I dev.

Post your comment

Subject:
Message:
0/1000 characters