VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Resolution Resize and Run Time Control Resize. Module for automatically resizing forms and controls

by Rahul Bagal (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 12th October 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Resolution Resize and Run Time Control Resize. Module for automatically resizing forms and controls with varying screen resolutions. To use it

API Declarations


' Place this code
' Resolution Resize and Run Time Control Resize.
'Module for automatically resizing forms and
'controls with varying screen resolutions. This is
'an adaptation of a Microsoft Knowledge Base
'article. The example worked as it was but half the
'code was on the form. I wanted a complete module
'to add to any app easily. To use it simply add
' "Call G_P_AdjustForm(Me)" to the Form_Load event
'and "Call G_P_FormResize(Me)" to the Form_Resize
'event. Also change the design time resolution
'values.

' I have Refered some another code
' Credits also goes to that author


Rate Resolution Resize and Run Time Control Resize. Module for automatically resizing forms and controls



Public Xtwips As Integer, Ytwips As Integer
Public Xpixels As Integer, Ypixels As Integer

Type FRMSIZE
   Height As Long
   Width As Long
End Type

Public RePosForm As Boolean
Public DoResize As Boolean
Dim MyForm As FRMSIZE
Dim DesignX As Integer
Dim DesignY As Integer
Dim ScaleFactorX As Single, ScaleFactorY As Single

 
Sub Resize_For_Resolution(ByVal SFX As Single, ByVal SFY As Single, MyForm As Form)
   Dim i As Integer
   Dim SFFont As Single
   SFFont = (SFX + SFY) / 2.2
   On Error Resume Next
   With MyForm
      For i = 0 To .Count - 1
         If TypeOf .Controls(i) Is ComboBox Then
            .Controls(i).Left = .Controls(i).Left * SFX
            .Controls(i).Top = .Controls(i).Top * SFY
            .Controls(i).Width = .Controls(i).Width * SFX
         ElseIf TypeOf .Controls(i) Is TextBox Then
            .Controls(i).Move .Controls(i).Left * SFX, _
            .Controls(i).Top * SFY, _
            .Controls(i).Width * SFX, _
            .Controls(i).Height
         Else
            .Controls(i).Move .Controls(i).Left * SFX, _
            .Controls(i).Top * SFY, _
            .Controls(i).Width * SFX, _
            .Controls(i).Height * SFY
         End If
         If TypeOf .Controls(i) Is vaSpread Then
         ' .Controls(i).FontSize = .Controls(i).FontSize * SFFont
         Else
         .Controls(i).FontSize = .Controls(i).FontSize * SFFont
         End If
      Next i
      If RePosForm Then
         .Move .Left * SFX, .Top * SFY, .Width * SFX, .Height * SFY
      End If
   End With
End Sub


Public Sub G_P_FormResize(TheForm As Form)
   Dim ScaleFactorX As Single, ScaleFactorY As Single
   If Not DoResize Then
      DoResize = True
      Exit Sub
   End If
   RePosForm = False
   ScaleFactorX = TheForm.Width / MyForm.Width
   ScaleFactorY = TheForm.Height / MyForm.Height
   Resize_For_Resolution ScaleFactorX, ScaleFactorY, TheForm
   MyForm.Height = TheForm.Height
   MyForm.Width = TheForm.Width
End Sub

Public Sub G_P_AdjustForm(TheForm As Form, Optional DX As Integer = 640, Optional DY As Integer = 480)
   Dim Res As String ' Returns resolution of system
   ' Put the design time resolution in here
   ' provide DX , DY as design time resolution of form
   ' i.e. the resulution of Programmers Machine
   DesignX = DX
   DesignY = DY
   RePosForm = True
   DoResize = False
   Xtwips = Screen.TwipsPerPixelX
   Ytwips = Screen.TwipsPerPixelY
   Ypixels = Screen.Height / Ytwips
   Xpixels = Screen.Width / Xtwips
   ScaleFactorX = (Xpixels / DesignX)
   ScaleFactorY = (Ypixels / DesignY)
   TheForm.ScaleMode = 1
   Resize_For_Resolution ScaleFactorX, ScaleFactorY, TheForm
   Res = Str$(Xpixels) + "  by " + Str$(Ypixels)
   'Debug.Print Res
   MyForm.Height = TheForm.Height
   MyForm.Width = TheForm.Width
End Sub




Download this snippet    Add to My Saved Code

Resolution Resize and Run Time Control Resize. Module for automatically resizing forms and controls Comments

No comments have been posted about Resolution Resize and Run Time Control Resize. Module for automatically resizing forms and controls. Why not be the first to post a comment about Resolution Resize and Run Time Control Resize. Module for automatically resizing forms and controls.

Post your comment

Subject:
Message:
0/1000 characters