Results 1 to 9 of 9

Thread: Scaling form to a smaller screen

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455

    Post

    Dear VB programmers,

    I have made a big Form for a 21" screen.
    When I place this Form on a 15" screen, the form walks out of the screen.
    Is there a possibility to scale the form so it looks good on a smaller screen?

    Nice greetings,

    Michelle.

  2. #2
    Addicted Member
    Join Date
    Oct 1999
    Posts
    232

    Post

    You must use Screen object. Put follow code to form load event:

    With Screen
    Width = .Width
    Height = .Height
    End With

    Best regards.

    ------------------
    smalig
    [email protected]
    smalig.tripod.com

  3. #3
    Fanatic Member coox's Avatar
    Join Date
    Oct 1999
    Posts
    550

    Post

    Smalig, I'm interested in this one too. Using the Screen thing is fine for just resizing the form, but suppose you want ALL the controls scaled too? And fonts, etc....

  4. #4
    Junior Member
    Join Date
    Oct 1999
    Location
    Rijswijk, Holland
    Posts
    25

    Post

    When using a good vidio card, you can select a more pixels format as your 21" screen, the form will shown correctly on your screen.

    Ingrid.

  5. #5
    Lively Member
    Join Date
    Apr 1999
    Location
    India
    Posts
    73

    Post

    hi u can use this but its a very complicated thing....one ocx that was previously supplied with vb6 Resize does it perfectly.
    u can also do it yrself. but in that case u need to tapped the rezise event and need to scale each and every control according to the change in the size of the form.
    feel free to drop a mail if u need more help on this.
    thanx Manish

  6. #6
    Addicted Member
    Join Date
    Oct 1999
    Posts
    232

    Post

    Yes, my code only for form resizing. It's better for forms like win explorer, which have big textarea, list and etc (but not buttons!). Window resize with many controls - it is not so good idea. Look at style of microsoft. I like it. If you have buttons toolbar like adobe photoshop you can use picture object. Place a picture on the form, then place your buttons on the picture. If you must resize this form you move only picture. The buttons and fonts do not change the size usually.

    Best regards.

    ------------------
    smalig
    [email protected]
    smalig.tripod.com

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Michelle, the physical size of the monitor has nothing to do with how your form is displayed. Here is what VB Books Online has to say.
    Designing Resolution-independent Forms
    By default, Microsoft Visual Basic doesn't change your form and control sizes as you change screen resolutions. What this means is that a form that you design at 1024 by 768 resolution may extend past the edges of the screen when run at 640 by 480 resolution. If you want to create forms and controls that have the same proportions no matter what screen resolution you use, you must either design your forms at the lowest resolution, or add code to your program that changes the forms.
    The easiest way to avoid sizing problems is to design your forms at 640 by 480 resolution. If you prefer to work at a higher resolution, you still need to be aware of how your form will appear at a lower resolution. One way to do this is to create a 640 by 480 pixel solid color bitmap and assign it to the Picture property of your form. You can then place your controls within the boundaries of the bitmap at design time. Don't forget to remove the bitmap once you're done with the design.
    Visual Basic also places your form at run time based on its location at design time. If you are running at 1024 by 768 resolution at design time and you place a form in the lower right-hand corner of the screen, it may not be visible when run at a lower resolution. You can avoid this by positioning your form with code in the Form Load event:
    Private Sub Form_Load()
    Me.Move 0, 0
    End Sub

    This has the same effect as setting both the Left and Top properties of the form to 0, but the Move method accomplishes it in a single step.
    Visual Basic uses a device-independent unit of measurement, a twip, for calculating size and position. Two properties of the Screen object, TwipsPerPixelX and TwipsPerPixelY, can be used to determine the size of the display at run time. Using these properties, you can write code to adjust the size and position of your forms and controls:
    Private Sub SetControls()
    Dim X As Integer
    Dim Y As Integer

    X = Screen.TwipsPerPixelX
    Y = Screen.TwipsPerPixelY
    Select Case X, Y
    Case 15, 15
    ' Resize and move controls.
    txtName.Height = 200
    txtName.Width = 500
    txtName.Move 200, 200
    ' Add code for other resolutions.

    End Sub

    You also need to be aware of the position of Visual Basic's own windows at design time. If you position the Project window to the right side of the screen at high resolution, you may find that it is no longer accessible when you open your project at a lower resolution.


    Some time ago I wrote a routine that scales forms to fit various screen resolutions. It was designed only to enlarge forms, but you can modify it as you like. It also does not scale the title bar or menus. If you are interested, email me and I'll send it to you.


    ------------------
    Marty

  8. #8
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290

    Post

    There is code on this site for changing the resolution of the monitor to whatever you want. I think you should design the form, then in the form load event call the routine to change the user's screen resolution.

    I have not used this yet - are there pitfalls to this method?

  9. #9
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Of course there are pitfalls to resizing the user's screen size. Suppose they have an older monitor, that does not support anything above 800x600. And you write your code to resize their screen for 1024x768. Guess what happens to their monitor. *PooF* They see nothing of the program that you spent hundreds of hours and many months designing, all they see is a bunch of flickering lines that will not go away. So, if you decide to resize the user's screen, either put a warning at the startup of your program which says something to the effect of: "This program will resize your screen resolution to 1024x768. If this is a problem for your monitor, please hit cancel." And then if they hit cancel, make your program stop. However, I have always thought that it is better for the programmer to accomodate the user, rather than making the user accomodate the program. So I would try to make your program work with the setup that the user has, instead of trying to change the user's setup. Because, remember, if you change the resolution, you have to change it back to it's orginal setting when your program is done, or if they perhaps Alt-Tab out of your program. Just something to think about.

    ------------------
    Thanks,
    Ryan
    [email protected]
    ICQ# 47799046

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width