×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-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!
  • Students Click Here

*Eng-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

Jobs

Hi there: I am kind of new desig

Hi there: I am kind of new desig

Hi there: I am kind of new desig

(OP)
Hi there:

I am kind of new designing forms in Visual Basic 6. I have design some forms in a 1024 by 768 pixels when the program is run in a 800 by 600 pixel screen area part of the form falls outside the screen. Is there a routine to change the program screen properties to what ever the computer that the program is run the screen area is set? I have looked into the windows API functions (I think there is the solution) but no answer found yet. Any help will be very appreciated.

Rafael

Rafael

RE: Hi there: I am kind of new desig

The best way is to start designing in 800 x 600. This is the most used, especially by 14 inch monitors. Use TrueType fonts like Arial. Test your application at 640 x 480 before you deploy it.

Regards

Steven van Els
SAvanEls@cq-link.sr

RE: Hi there: I am kind of new desig

I found this while perusing one of my favorite sites for VB Info www.mvps.org/vbnet/

Hope it helps.

HOWTO: Create a Resolution-Independent Form

--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual Basic Learning Edition for Windows, versions 5.0, 6.0
Microsoft Visual Basic Professional Edition for Windows, versions 5.0, 6.0
Microsoft Visual Basic Enterprise Edition for Windows, versions 5.0, 6.0
Microsoft Visual Basic Standard Edition, 32-bit only, for Windows, version 4.0
Microsoft Visual Basic Professional Edition, 16-bit only, for Windows, version 4.0
Microsoft Visual Basic Professional Edition, 32-bit, for Windows, version 4.0
Microsoft Visual Basic Enterprise Edition, 16-bit, for Windows, version 4.0
Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows, version 4.0

--------------------------------------------------------------------------------


SUMMARY
If a Form takes up most of the screen at 640 x 480 (VGA) resolution, it only takes 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 for an Single Document Interface (SDI) application. It does not address special considerations for Multiple Document Interface (MDI) applications.



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, do 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 adjusts the Height. Other controls may not have a FontSize property and need some other property set to make FontSize appear correctly.


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


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


Add a Label, a CommandButton, and any other types of controls you would like to test.


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
 
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
           ' Be sure to resize and reposition before changing the FontSize
           .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 adjusts for the new resolution.

RE: Hi there: I am kind of new desig

(OP)
Hi There:

Thanks for your help. It has been very helpful
Appreciated.

Rafael  

Rafael

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 Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

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

Click Here to join Eng-Tips and talk with other members!


Resources