Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6509
  • Last Modified:

VB6 - setting form size in pixels

Hi,

I'm trying to set the form design property so it has a size of 1280 x 768 pixels - thing is, I can't figure out how to do this. I've set the ScaleWidth and ScaleHeight to 1280 and 768 respectively, but I can't be sure that this has worked as intended. Help?

Thanks,
Uni
0
Unimatrix_001
Asked:
Unimatrix_001
  • 4
  • 4
1 Solution
 
Frosty555Commented:
The form's width/height itself, though, is always measured in twips. Regardless of the scalemode property.

If you change form's scalemode property to "pixels". All sub-objects inside the form will now use "pixel" width and heights. So a label or button or textbox will use regular pixel sizing like you would expect.

The form, however is always in twips. You can get the ratio between twips and pixels using Screen.twipsperpixelx and Screen.twipsperpixely. So if you want your form to always be 1280x768 put in your form's LOAD event:

      Form1.Width = 1280 * Screen.TwipsPerPixelX
      Form1.Height = 768 * Screen.TwipsPerPixelY


1
 
Unimatrix_001Author Commented:
Hi Frosty, ok thanks - although how can I do this at design time when I'm laying out the components for a single resolution?
0
 
Frosty555Commented:
Forgot to mention:

Consider the Form.ScaleWidth and Form.ScaleHeight properties to be *read only*. If you change them, you do not change the size of the form. Instead, you change the ratio of twips to "form units", and thus the Form's scalemode property will automatically get set to "user".

Use the scalewidth and scaleheight when you need to figure out what the size of the form is. Use the width/height multiplied by twipsperpixel when you want to set the size.

You might notice picturebox's have their own scalemode/scalewidth/scaleheight properties. They act just like forms: The picturebox's width will always be whatever the form was set to. Objects INSIDE of the picturebox will have width/height based on the scalemode of the picturebox.

So if you are putting picturebox's on your form and using it like a container (putting other objects inside your picturebox), make sure you set your picturebox's scalemode too.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Frosty555Commented:
Form width and height is always measured in twips.

Twips are a measure of size that is dependant on the DPI of the user's computer. With normal size fonts (72 dpi), 1 twip = 15 pixel, but on many new laptops, a "large" font of 120dpi is used, and in this case one twip is more than 15 pixels.

Since form width and height is always measured in twips, you cannot set this at design time. You must set it in code. For visual sake, you may set the form's width and height to be equal to 19200 x  11520, but be aware that this is a measurement in twips, and changing your DPI size, or moving to another computer with a different DPI size, will cause the form to no longer be 1280x768 pixels, unless you explicitely resize the form in it's Form_Load() event.

You should probably get in the habit of using twips though, it makes your program easily scale for users who do not use standard DPI settings. Only use pixels if you have a real reason to.
0
 
Unimatrix_001Author Commented:
I'm slowly getting my head around the idea of using twips, although:

You should probably get in the habit of using twips though, it makesyour program easily scale for users who do not use standard DPIsettings. Only use pixels if you have a real reason to.You should probably get in the habit of using twips though, it makes your program easily scale for users who do not use standard DPI settings. Only use pixels if you have a real reason to.

This confuses me a bit - how can I design my program for X, Y twips and expect it to look the same if it is ran on a computer with W, Z twips?
0
 
Frosty555Commented:
VB internally converts all twip units into pixels just before drawing it on the screen. The ratio of twips to pixels changes with the DPI.

If you use twips as your unit, if the program is run on a computer with a higher DPI setting the fonts will scale up, but so will the form size, the size of the buttons and labels, and everything else on the form, because twips vary with DPI too. Everything will appear "bigger" as you would expect it to.

If you use pixels, and you run your program on a computer where somebody has cranked up the DPI, all the fonts will be bigger but the form and object positions / sizes will stay the same, resulting in a crowded form where everything is clipping and overlapping. Potentially some things may be unreadable or unusable as a result.

In the old days, this wasn't a problem, since so few people actually changed the DPI settings, but a lot of modern laptops come with 120dpi set as a standard... so you need to accomodate that.
0
 
Unimatrix_001Author Commented:
Thank you - you've cleared a lot up for me. :-)
0
 
Unimatrix_001Author Commented:
:)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now