×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Form Displaying In Different Size Monitors

Form Displaying In Different Size Monitors

Form Displaying In Different Size Monitors

(OP)
I work with an 17" monitor where I do all my programming. However when I try to run my programs in different size monitors (14" or 15" ) the forms do not display full size screen as when I develop them on my 17" monitor. They display with a lot of empty space around them.
Please help and thanks in advance.
Alexis

Alexis
alexisale@msn.com

RE: Form Displaying In Different Size Monitors

The following was taken directly from the M$ Knowledge Base
of information. Perhaps the contents will assist you in
correcting your problem of having a resolution independent
display. The example is quite lengthy ...

Jim - aka Logit

HOWTO: Create a Resolution-Independent Form
The information in this article applies to:
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 16-bit and 32-bit, for Windows, version 4.0


SUMMARY
If a Form takes up most of the screen at 640 x 480 (VGA) resolution, it will only take up a small portion of the screen at 1600 x 1200. Normally, this is exactly what you want to happen, but some circumstances arise where you want a Form to retain the same proportional size and position regardless of screen resolution. This article discusses a simple way to accomplish this.



MORE INFORMATION
When designing Forms to be resized at run-time, keep the following in mind:

When designing Forms, it is best to design them for the lowest screen resolution you expect users to run. Even using the technique outlined here, it is best to stay with this rule because Forms resize better going to higher resolutions than they do going to lower ones.
Use TrueType Fonts because they are scalable. Also, try to use Fonts that will be available on the user's system. Otherwise, a substituted Font may not scale properly.
Because resizing may not always be exact, especially with Fonts, make the controls a little larger than the minimum necessary. Also, try to leave a little space between controls.
Some controls, like CheckBoxes and Option buttons, will not resize, and some controls may require special handling. For example, the Height property of ComboBoxes is read-only at run-time, but changing the font size will adjust the Height.

Step-by-Step Example
1. Change the video resolution to 800 x 600.

2. Start a new project in Visual Basic. Form1 is created by default.

3. Add a Label, a CommandButton, and any other types of controls you would

like to test.

4. Copy the following code into the Form's module:

Option Explicit

Dim MyForm As FRMSIZE
Dim DesignX As Integer
Dim DesignY As Integer

Private Sub Form_Load()
Dim ScaleFactorX As Single, ScaleFactorY As Single ' Scaling factors
' Size of Form in Pixels at design resolution
DesignX = 800
DesignY = 600
RePosForm = True ' Flag for positioning Form
DoResize = False ' Flag for Resize Event
' Set up the screen values
Xtwips = Screen.TwipsPerPixelX
Ytwips = Screen.TwipsPerPixelY
Ypixels = Screen.Height / Ytwips ' Y Pixel Resolution
Xpixels = Screen.Width / Xtwips ' X Pixel Resolution

' Determine scaling factors
ScaleFactorX = (Xpixels / DesignX)
ScaleFactorY = (Ypixels / DesignY)
ScaleMode = 1 ' twips
'Exit Sub ' uncomment to see how Form1 looks without resizing
Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me
Label1.Caption = "Current resolution is " & Str$(Xpixels) + _
" by " + Str$(Ypixels)
MyForm.Height = Me.Height ' Remember the current size
MyForm.Width = Me.Width
End Sub

Private Sub Form_Resize()
Dim ScaleFactorX As Single, ScaleFactorY As Single

If Not DoResize Then ' To avoid infinite loop
DoResize = True
Exit Sub
End If

RePosForm = False
ScaleFactorX = Me.Width / MyForm.Width ' How much change?
ScaleFactorY = Me.Height / MyForm.Height
Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me
MyForm.Height = Me.Height ' Remember the current size
MyForm.Width = Me.Width
End Sub

Private Sub Command1_Click()
Dim ScaleFactorX As Single, ScaleFactorY As Single

DesignX = Xpixels
DesignY = Ypixels
RePosForm = True
DoResize = False
' Set up the screen values
Xtwips = Screen.TwipsPerPixelX
Ytwips = Screen.TwipsPerPixelY
Ypixels = Screen.Height / Ytwips ' Y Pixel Resolution
Xpixels = Screen.Width / Xtwips ' X Pixel Resolution

' Determine scaling factors
ScaleFactorX = (Xpixels / DesignX)
ScaleFactorY = (Ypixels / DesignY)
Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me
Label1.Caption = "Current resolution is " & Str$(Xpixels) + _
" by " + Str$(Ypixels)
MyForm.Height = Me.Height ' Remember the current size
MyForm.Width = Me.Width
End Sub

5. Add a Module from the Project menu and paste in the following code:

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

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 ' average scale
' Size the Controls for the new resolution
On Error Resume Next ' for read-only or nonexistent properties
With MyForm
For I = 0 To .Count - 1
If TypeOf .Controls(I) Is ComboBox Then ' cannot change Height
.Controls(I).Left = .Controls(I).Left * SFX
.Controls(I).Top = .Controls(I).Top * SFY
.Controls(I).Width = .Controls(I).Width * SFX
Else
.Controls(I).Move .Controls(I).Left * SFX, _
.Controls(I).Top * SFY, _
.Controls(I).Width * SFX, _
.Controls(I).Height * SFY
End If
.Controls(I).FontSize = .Controls(I).FontSize * SFFont
Next I
If RePosForm Then
' Now size the Form
.Move .Left * SFX, .Top * SFY, .Width * SFX, .Height * SFY
End If
End With
End Sub

Try running this under different screen resolutions and the Form should take up the same desktop area and retain its look and screen position. You may notice that your design resizes better when changing to a higher resolution than it does when changing to a lower one. You can also use the Mouse to Resize the Form and it will re-scale automatically. Finally, if you change video resolution while the Form is open, you can click on Command1 and it will adjust for the new resolution.


REFERENCES
For additional information, please see the following article in the Microsoft Knowledge Base:


ARTICLE-ID: Q187562
TITLE : HOWTO: Resize the Controls in SSTab When Form is Resized

Additional query words: scale kbVBp400 kbVBp500 kbDisplay kbForms kbVBp
Version : WINDOWS:4.0,5.0
Platform : WINDOWS
Issue type : kbhowto


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close