Search Tools Links Login

Resize a form based on display settings


Resizes a form based on the display settings

Original Author: ROBERT JACKSON

Assumptions

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

Code


'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

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 89 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.