tags:

views:

53

answers:

2

I need my vb6 application to open to a precise dimensions, in pixels. How do I do this?

+1  A: 

Use the Height and Width properties of your forms. Since the unit of measure for these properties is twips, you need to convert pixels to twips. For this you can use the Screen,TwipsPerPixelX and Screen,TwipsPerPixelY proeprties.

Do something like this in Form_Load:

Me.Width = formWidthPixels * Screen.TwipsPerPixelX
Me.Height = formHeightPixels * Screen.TwipsPerPixelX

Where formWidthPixels and formHeightPixels are the width and height in pixels you want your forms.

Jay Riggs
+1. But do bear in mind that Height and Width include the menu bar and borders, which are different thicknesses with different themes or font sizes or on different versions of Windows. So you can't predict how much room there will be in the form for your content - your controls or whatever. You will need to write some code to resize your form contents into the available ScaleWidth and ScaleHeight space after the form has loaded (it's a bit like making a resizable form).
MarkJ
When I try the above, I get the following error:Run-time error '380': Invalid property value
stan g
I assume you're using the two lines I suggested above.. 1. What's the pixel value you're attempting to set?2. Does either line run without error?3. Where are you running this code (in Form_Load, somewhere else)?
Jay Riggs
A: 

Above solution not working, I am using the lines suggested, in Form_Load:

Me.Width = 1215 * Screen.TwipsPerPixelX
Me.Height = 780 * Screen.TwipsPerPixelX

Neither line works, with any values, I keep getting the error described above.

stan g