Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resize forms and controls based on screen resolution

Status
Not open for further replies.

SHAWTY721

Programmer
Aug 16, 2007
116
US
I have a vb6 application where I am trying to change the form size and the form controls based on the users screen resolution. I have gotten the size of the form to change based on the screen resolution but the controls are staying the same size. Can anyone help me figure this out. Here is what the module looks like that contains the code.

<CODE>
Option Explicit

Public iHeight As Integer
Public iWidth As Integer
Public x_size As Double
Public y_size As Double
Public List() As Control
Public curr_obj As Object

Public Type RECT
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type

Public Declare Function GetDesktopWindow Lib "User32" () As Long
Public Declare Function GetWindowRect Lib "User32" _
(ByVal hWnd As Long, rectangle As RECT) As Long

Public Sub UserForm_Activate(UserForm1 As Form)
Dim r As RECT
Dim hWnd As Long
Dim RetVal As Long
Dim ScrRes As String
Dim FtSz As Integer
Dim curScreen As Object

hWnd = GetDesktopWindow()
RetVal = GetWindowRect(hWnd, r)

ScrRes = (r.x2 - r.x1) & "X" & (r.y2 - r.y1)

'Use ScrRes variable to decide how to size the userform.

' If ScrRes = "640X480" Then
' With UserForm1
' UserForm1.Width = 7680
' UserForm1.Height = 5760
' End With
If ScrRes = "800X600" Then
With UserForm1
UserForm1.Width = 11140
UserForm1.Height = 9000
End With
ElseIf ScrRes = "1024X768" Then
With UserForm1
UserForm1.Width = 11428
UserForm1.Height = 9612
End With
ElseIf ScrRes = "1280X800" Then
With UserForm1
UserForm1.Width = 14500
UserForm1.Height = 9600
End With
ElseIf ScrRes = "1360X768" Then
With UserForm1
UserForm1.Width = 15460
UserForm1.Height = 9612
End With
ElseIf ScrRes = "1680X1050" Then
With UserForm1
UserForm1.Width = 15940
UserForm1.Height = 10500
End With
End If

End Sub
</CODE>
 
Put whatever controls you want resized in the form resize event.
For example:

Private Sub Form_Resize()
Command1.Left=0
Command1.Width=UserForm1.ScaleWidth/2
Command2.Left=UserForm1.ScaleWidth/2
Command2.Width=UserForm1.ScaleWidth/2
End Sub

This changes the Command1 and Command2 controls to be half the width of the form.
 
You could also look at Microsoft's answer, repeated in faq222-3453

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top