Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General / July 2004



Tip: Looking for answers? Try searching our database.

using different screen resolutions in VB

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marco Krechting - 30 Jul 2004 12:52 GMT
Hi All,

I'm creating a VB program in a 1024-768 screen resolution.
The program is however also used on a screen which uses 1280-1024.

I have a MDI main form on which I want to load childforms like:

 HVT.Move 0, 0, Me.ScaleWidth - 4900, Me.ScaleHeight - 2400

This works fine with my screen resolution but on the other PC I get
very strange form sizes.

Is there a way to create something that recons with the screen resolution
and adapts the sizes of the forms?

Regards
Marco
The Netherlands
Jan Hyde - 30 Jul 2004 13:15 GMT
"Marco Krechting" <marcokrechting@zonnet.nl>'s wild thoughts
were released on Fri, 30 Jul 2004 13:52:47 +0200 bearing the
following fruit:

>Hi All,
>
>I'm creating a VB program in a 1024-768 screen resolution.

Uh oh!

>The program is however also used on a screen which uses 1280-1024.

Thats OK.

>I have a MDI main form on which I want to load childforms like:
>
>  HVT.Move 0, 0, Me.ScaleWidth - 4900, Me.ScaleHeight - 2400
>
>This works fine with my screen resolution but on the other PC I get
>very strange form sizes.

Your using fixed values, (4900,2400) which I assume you
calculated using your screen res. You shouldn't hard code
the values but instead calcualte the values based on screen
size.

>Is there a way to create something that recons with the screen resolution
>and adapts the sizes of the forms?

As above.

Jan Hyde (VB MVP)

Signature

f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.

[Abolish the TV License - http://www.tvlicensing.biz/]

Marco Krechting - 30 Jul 2004 13:25 GMT
Jan,

Thanks

How can I calculate these values?
I found out that I have screenwidth 15360 and height 11520

and at the office I have screenwidth 19200 and height 15360

Is that something I should use?

Marco

> "Marco Krechting" <marcokrechting@zonnet.nl>'s wild thoughts
> were released on Fri, 30 Jul 2004 13:52:47 +0200 bearing the
[quoted text clipped - 28 lines]
>
> Jan Hyde (VB MVP)
Jan Hyde - 30 Jul 2004 14:41 GMT
"Marco Krechting" <marcokrechting@zonnet.nl>'s wild thoughts
were released on Fri, 30 Jul 2004 14:25:22 +0200 bearing the
following fruit:

>Jan,
>
[quoted text clipped - 4 lines]
>
>and at the office I have screenwidth 19200 and height 15360

How did you come to the values 4900,2400 in the first place?
Whatever calculation was used to determine these values is
the calculation you need to perform.

>Is that something I should use?

You should always use the relevant objects values eg,

For an MDI child form, use the MDIForm's scalewidth & height

For the MDIForm use the screen.width and height(*)

In general you look to the container of the object you want
to size for relevant dimensions

And remember, it's easy to cater for bigger screen sizes,
but very difficult to cater for smaller ones. So you should
always design your apps for the smallest screen size you
intend to support.

J

>Marco
>
[quoted text clipped - 30 lines]
>>
>> Jan Hyde (VB MVP)

Jan Hyde (VB MVP)

Signature

Tangent: A sunburned man. (Pierre Abbat)

[Abolish the TV License - http://www.tvlicensing.biz/]

Marco Krechting - 30 Jul 2004 14:46 GMT
> How did you come to the values 4900,2400 in the first place?
> Whatever calculation was used to determine these values is
> the calculation you need to perform.

There was no calculation. I changed the values and tried until I had the
right ones.

> In general you look to the container of the object you want
> to size for relevant dimensions

What does that mean?
Can you give me one example of how this should look?

Marco

> "Marco Krechting" <marcokrechting@zonnet.nl>'s wild thoughts
> were released on Fri, 30 Jul 2004 14:25:22 +0200 bearing the
[quoted text clipped - 67 lines]
>
> Jan Hyde (VB MVP)
Jan Hyde - 30 Jul 2004 15:00 GMT
"Marco Krechting" <marcokrechting@zonnet.nl>'s wild thoughts
were released on Fri, 30 Jul 2004 15:46:33 +0200 bearing the
following fruit:

>> How did you come to the values 4900,2400 in the first place?
>> Whatever calculation was used to determine these values is
[quoted text clipped - 7 lines]
>
>What does that mean?

I though I had explained this in the bit you removed when
you quoted my reply.

>Can you give me one example of how this should look?

Start a new project and add a label to the form.

Add this code

Private Sub Form_Load()

 '-- Size the form to fill the left half of the screen
 Me.Move 0, 0, Screen.Width / 2, Screen.Height
End Sub

Private Sub Form_Resize()
 '-- Always make the label cover the left half of the form
 Label1.BackColor = vbRed
 Label1.Move 0, 0, Me.ScaleWidth / 2, Me.ScaleHeight

End Sub

Now run it, try changing the size of the form and notice how
the label will *always* cover half the form.

Try changing to a different screen res and run the project
again. Notice that whatever screen res you run the project
in, the form always covers half the screen.

The label is sized relative to the form (it's container)
The form is sized relative to the screen (it's container)

I could have written

Label1.Move 0, 0, 2940,  8595

and that would look fine on my screen res, but when I moved
the form to a different size, or ran in a different screen
res, it would not be correct.

>> "Marco Krechting" <marcokrechting@zonnet.nl>'s wild thoughts
>> were released on Fri, 30 Jul 2004 14:25:22 +0200 bearing the
[quoted text clipped - 68 lines]
>>
>> Jan Hyde (VB MVP)

Jan Hyde (VB MVP)

Signature

The average guy thinks about sex once every six tits

[Abolish the TV License - http://www.tvlicensing.biz/]

Ken Halter - 30 Jul 2004 17:34 GMT
Adding to other replies... keep in mind that your 4900,2400 are in
Twips. That means... if the user has their system set to Small Fonts,
the box will be 326x160 pixels....

'immediate window
?4900/15
 326.666666666667
?2400/15
 160

....but if the system's set to Large Fonts, that box will be 408x200
pixels....

'immediate window
?4900/12
 408.333333333333
?2400/12
 200

... and if they have their system set to Custom Fonts, who knows how big
the box will be.

The safest way to deal with it is to always use Pixels in your
calculation.. even if your form's set to use Twips.

MyBox.Move 326 * Screen.TwipsPerPixelX, 160 * Screen.TwipesPerPixelY

>>How did you come to the values 4900,2400 in the first place?
>>Whatever calculation was used to determine these values is
[quoted text clipped - 85 lines]
>>
>>Jan Hyde (VB MVP)

Signature

Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..

Bob Butler - 30 Jul 2004 17:53 GMT
> The safest way to deal with it is to always use Pixels in your
> calculation.. even if your form's set to use Twips.
>
> MyBox.Move 326 * Screen.TwipsPerPixelX, 160 * Screen.TwipesPerPixelY

I often find the ScaleX and ScaleY methods easier to work with:

mybox.move
me.scalex(326,vbPixels,me.ScaleMode),Me.ScaleY(160,vbPixels,Me.ScaleMode)

It's more typing but tells me immediately that I'm setting it to 326x160
pixels regardless of the scalemode of the container

Signature

Reply to the group so all can participate
VB.Net... just say "No"

Rick Rothstein - 30 Jul 2004 14:51 GMT
> How can I calculate these values?
> I found out that I have screenwidth 15360 and height 11520
>
> and at the office I have screenwidth 19200 and height 15360
>
> Is that something I should use?

Type the following into VB's Immediate window...

    Print Screen.Width, Screen.Height

Do the numbers that print out look familiar? Use the Screen objects
Height and Width to get the user's screen size.

Rick - MVP
YYZ - 30 Jul 2004 16:28 GMT
> Hi All,
>
[quoted text clipped - 7 lines]
> This works fine with my screen resolution but on the other PC I get
> very strange form sizes.

So, you want your child form to be positioned in the top left of the MDI child
space, and span all but 327 pixels from the right and 160 pixels from the
bottom.  ???  Why is that?  I'd probably find out how big that makes your child
for on YOUR machine, and then instead of doing Me.ScaleWidth - 4900 I'd just put
in the correct # of twips for the width and the height.

And, actually, I'd figure out what the size is in pixels.  Do that by taking the
size in twips that you get / Screen.TwipsPerPixelX or Y.  Then use THAT number
in your code, and multiply it by Screen.TwipsPerPixelX (or Y, depending on the
dimension you are sizing) at RUNTIME, not design time.

Or, if you really do want to keep the same dimensions based from the width and
height if your mdiform, then still replace the 4900 and 2400 with the pixel
value that that correlates to on your machine (I'm betting approx. 327 x 160)
and still, at RUNTIME multiply it by Screen.TwipsPerPixelX (or Y).

Matt
Paul Clement - 30 Jul 2004 17:39 GMT
¤ Hi All,
¤
¤ I'm creating a VB program in a 1024-768 screen resolution.
¤ The program is however also used on a screen which uses 1280-1024.
¤
¤ I have a MDI main form on which I want to load childforms like:
¤
¤   HVT.Move 0, 0, Me.ScaleWidth - 4900, Me.ScaleHeight - 2400
¤
¤ This works fine with my screen resolution but on the other PC I get
¤ very strange form sizes.
¤
¤ Is there a way to create something that recons with the screen resolution
¤ and adapts the sizes of the forms?

One of few times I recommend investing in a component to handle this for you:

http://www.lyoung.com

Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.