VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Resize a form based on display settings

by ROBERT JACKSON (1 Submission)
Category: VB function enhancement
Compatability: Visual Basic 3.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

Resizes a form based on the display settings

Assumes
How to declare an API in global module
Side Effects
You may have to play with the size to find the right percentage
API Declarations
'Declare this code in your global module
Global Const SM_CXSCREEN = 0
Global Const SM_CYSCREEN = 1
Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long

Rate Resize a form based on display settings


'Use this sub in the form you are coding, it could be improved to be a global procedure
'and pass the form as an argument.
Private Sub Resizeall()
Dim Ctl As Control
 Dim X As Integer
  
   Dim Size As Double
   ScreenX = GetSystemMetrics(SM_CXSCREEN)

 ScreenY = GetSystemMetrics(SM_CYSCREEN)
  
' this picks out the display settings.
Select Case ScreenX
    Case 640
         'size = 0.67
        Size = 0.64
    Case 800
        Size = 0.72
    Case 1024
        Exit Sub
    Case 1280
      'Exit Sub
      Size = 1.25
    Case Else
      Exit Sub
  End Select
  'Me.Height = Me.Height * size
  'Me.Top = Me.Top * size
  'Me.Width = Me.Width * size
  'Me.Left = Me.Left * size
  For Each Ctl In Me.Controls
  
   Ctl.Height = Ctl.Height * Size
   Ctl.Width = Ctl.Width * Size
   Ctl.Top = Ctl.Top * Size
   Ctl.Left = Ctl.Left * Size
   If TypeOf Ctl Is TextBox Or TypeOf Ctl Is Label Or TypeOf Ctl Is CommandButton Then
   'Ctl.SizeToFit
   Ctl.FontName = "Arial"
   Ctl.FontSize = 6.7
   If TypeOf Ctl Is CommandButton Then
   Ctl.FontName = "Arial"
   Ctl.FontSize = 5
   End If
   End If
  
  'SizeToFit
   
  Next Ctl
  
End Sub

Download this snippet    Add to My Saved Code

Resize a form based on display settings Comments

No comments have been posted about Resize a form based on display settings. Why not be the first to post a comment about Resize a form based on display settings.

Post your comment

Subject:
Message:
0/1000 characters