Link to home
Start Free TrialLog in
Avatar of adrianmak
adrianmak

asked on

scolling in a form

I have designed a VB form in my PC which screen resolution is 800x600. But when I run the form an an PC which is 640x48, the form cannot be fully display all control.
How do provide a scoll bar in the form so that screen which is lower than 800x600 can scoll the form  .
Avatar of KDivad
KDivad

In the form load event, check the screen size. If it's too small, make two scrollbars visible, one along the bottom and one up the right side. Set their Max value to the difference between the screen size you need and the screen size you have. So if it needs 800x600 and you have 640x480, then 800 - 640 will give you 160 (I would divide it by ten and make the bottom scrollbar's Max value be 16) and 600 - 480 gives you 120 (or 12). Then in the Scrollbars' change events, just move all the controls on the form.
ASKER CERTIFIED SOLUTION
Avatar of Mirkwood
Mirkwood

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You might also try scaling all of the controls as percentages of Form.ScaleHeight and Form.ScaleWidth. This code will resize the controls when the form loads, or the user changes the size manually. You might have to use Form1.Height instead, but I think that one includes the title bar at the top. ScaleHeight is the height of the usable area of the form.

Private Sub Form_Resize()

Text1.ScaleHeight = Form1.ScaleHeight * 0.90
Text1.Top = Form1.ScaleHeight * 0.10
Text1.ScaleWidth = Form1.ScaleWidth
Text1.Left = 0

Command1.ScaleHeight = Form1.ScaleHeight * 0.10
Command1.Top = 0
Command1.ScaleWidth = Form1.ScaleWidth * 0.50
Command1.Left = 0

Command2.ScaleHeight = Form1.ScaleHeight * 0.10
Command1.Top = 0
Command1.ScaleWidth = Form1.ScaleWidth * 0.50
Command1.Left = Form1.ScaleWidth * 0.50

End Sub

When the form loads in the smaller screen, all of the controls are proportionally reduced to fit. The size of the fonts you use might also have to be scaled, if the text (as for Command1), runs off the edge of the resized control.


Or this, if you want it to work right

Command2.ScaleHeight = Form1.ScaleHeight * 0.10
Command2.Top = 0
Command2.ScaleWidth = Form1.ScaleWidth * 0.50
Command2.Left = Form1.ScaleWidth * 0.50