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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Displaying In Different Size Monitors

Status
Not open for further replies.

alexisa

MIS
Nov 20, 1998
4
US
I work with an 17&quot; monitor where I do all my programming. However when I try to run my programs in different size monitors (14&quot; or 15&quot; ) the forms do not display full size screen as when I develop them on my 17&quot; monitor. They display with a lot of empty space around them. <br>
Please help and thanks in advance.<br>
Alexis <p>Alexis<br><a href=mailto:alexisale@msn.com>alexisale@msn.com</a><br><a href= > </a><br>
 
The following was taken directly from the M$ Knowledge Base<br>
of information. Perhaps the contents will assist you in<br>
correcting your problem of having a resolution independent<br>
display. The example is quite lengthy ...<br>
<br>
Jim - aka Logit<br>
<br>
HOWTO: Create a Resolution-Independent Form<br>
The information in this article applies to: <br>
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0 <br>
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 16-bit and 32-bit, for Windows, version 4.0 <br>
<br>
<br>
SUMMARY<br>
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. <br>
<br>
<br>
<br>
MORE INFORMATION<br>
When designing Forms to be resized at run-time, keep the following in mind: <br>
<br>
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. <br>
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. <br>
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. <br>
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. <br>
<br>
Step-by-Step Example<br>
1. Change the video resolution to 800 x 600. <br>
<br>
2. Start a new project in Visual Basic. Form1 is created by default. <br>
<br>
3. Add a Label, a CommandButton, and any other types of controls you would <br>
<br>
like to test.<br>
<br>
4. Copy the following code into the Form's module: <br>
<br>
Option Explicit<br>
<br>
Dim MyForm As FRMSIZE<br>
Dim DesignX As Integer<br>
Dim DesignY As Integer<br>
<br>
Private Sub Form_Load()<br>
Dim ScaleFactorX As Single, ScaleFactorY As Single ' Scaling factors<br>
' Size of Form in Pixels at design resolution<br>
DesignX = 800<br>
DesignY = 600<br>
RePosForm = True ' Flag for positioning Form<br>
DoResize = False ' Flag for Resize Event<br>
' Set up the screen values<br>
Xtwips = Screen.TwipsPerPixelX<br>
Ytwips = Screen.TwipsPerPixelY<br>
Ypixels = Screen.Height / Ytwips ' Y Pixel Resolution<br>
Xpixels = Screen.Width / Xtwips ' X Pixel Resolution<br>
<br>
' Determine scaling factors<br>
ScaleFactorX = (Xpixels / DesignX)<br>
ScaleFactorY = (Ypixels / DesignY)<br>
ScaleMode = 1 ' twips<br>
'Exit Sub ' uncomment to see how Form1 looks without resizing<br>
Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me<br>
Label1.Caption = &quot;Current resolution is &quot; & Str$(Xpixels) + _<br>
&quot; by &quot; + Str$(Ypixels)<br>
MyForm.Height = Me.Height ' Remember the current size<br>
MyForm.Width = Me.Width<br>
End Sub<br>
<br>
Private Sub Form_Resize()<br>
Dim ScaleFactorX As Single, ScaleFactorY As Single<br>
<br>
If Not DoResize Then ' To avoid infinite loop<br>
DoResize = True<br>
Exit Sub<br>
End If<br>
<br>
RePosForm = False<br>
ScaleFactorX = Me.Width / MyForm.Width ' How much change?<br>
ScaleFactorY = Me.Height / MyForm.Height<br>
Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me<br>
MyForm.Height = Me.Height ' Remember the current size<br>
MyForm.Width = Me.Width<br>
End Sub<br>
<br>
Private Sub Command1_Click()<br>
Dim ScaleFactorX As Single, ScaleFactorY As Single<br>
<br>
DesignX = Xpixels<br>
DesignY = Ypixels<br>
RePosForm = True<br>
DoResize = False<br>
' Set up the screen values<br>
Xtwips = Screen.TwipsPerPixelX<br>
Ytwips = Screen.TwipsPerPixelY<br>
Ypixels = Screen.Height / Ytwips ' Y Pixel Resolution<br>
Xpixels = Screen.Width / Xtwips ' X Pixel Resolution<br>
<br>
' Determine scaling factors<br>
ScaleFactorX = (Xpixels / DesignX)<br>
ScaleFactorY = (Ypixels / DesignY)<br>
Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me<br>
Label1.Caption = &quot;Current resolution is &quot; & Str$(Xpixels) + _<br>
&quot; by &quot; + Str$(Ypixels)<br>
MyForm.Height = Me.Height ' Remember the current size<br>
MyForm.Width = Me.Width<br>
End Sub<br>
<br>
5. Add a Module from the Project menu and paste in the following code: <br>
<br>
Public Xtwips As Integer, Ytwips As Integer<br>
Public Xpixels As Integer, Ypixels As Integer<br>
<br>
Type FRMSIZE<br>
Height As Long<br>
Width As Long<br>
End Type<br>
<br>
Public RePosForm As Boolean<br>
Public DoResize As Boolean<br>
<br>
Sub Resize_For_Resolution(ByVal SFX As Single, _<br>
ByVal SFY As Single, MyForm As Form)<br>
Dim I As Integer<br>
Dim SFFont As Single<br>
<br>
SFFont = (SFX + SFY) / 2 ' average scale<br>
' Size the Controls for the new resolution<br>
On Error Resume Next ' for read-only or nonexistent properties<br>
With MyForm<br>
For I = 0 To .Count - 1<br>
If TypeOf .Controls(I) Is ComboBox Then ' cannot change Height<br>
.Controls(I).Left = .Controls(I).Left * SFX<br>
.Controls(I).Top = .Controls(I).Top * SFY<br>
.Controls(I).Width = .Controls(I).Width * SFX<br>
Else<br>
.Controls(I).Move .Controls(I).Left * SFX, _<br>
.Controls(I).Top * SFY, _<br>
.Controls(I).Width * SFX, _<br>
.Controls(I).Height * SFY<br>
End If<br>
.Controls(I).FontSize = .Controls(I).FontSize * SFFont<br>
Next I<br>
If RePosForm Then<br>
' Now size the Form<br>
.Move .Left * SFX, .Top * SFY, .Width * SFX, .Height * SFY<br>
End If<br>
End With<br>
End Sub<br>
<br>
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. <br>
<br>
<br>
REFERENCES<br>
For additional information, please see the following article in the Microsoft Knowledge Base: <br>
<br>
<br>
ARTICLE-ID: Q187562<br>
TITLE : HOWTO: Resize the Controls in SSTab When Form is Resized<br>
<br>
Additional query words: scale kbVBp400 kbVBp500 kbDisplay kbForms kbVBp <br>
Version : WINDOWS:4.0,5.0<br>
Platform : WINDOWS<br>
Issue type : kbhowto<br>
<br>
<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top