For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Syntax > March 2005 > Form Size XP Style vs Classic Style









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Form Size XP Style vs Classic Style
Bart Steur

2005-03-07, 4:09 pm

Hello,

I've goto a small problem. I've got an app that runs on two computers. One
of these computers has the Windows XP style Theme (green Start button,
rounded form corners) the other Windows Classic Theme (Gray start button,
sharp window corners).

My problem is that the same form in my app has a different height for each
style. The difference is 7 pixels (105 twips).

Is there a way to check what display style is running on the computer so I
can compensate for the 7 pixels., or maybe there is another (better) way.

Thanks,

B Steur


Jan Hyde

2005-03-07, 4:09 pm

"Bart Steur" <solnews@xs4all.nl>'s wild thoughts were
released on Mon, 7 Mar 2005 13:01:20 +0100 bearing the
following fruit:

>Hello,
>
>I've goto a small problem. I've got an app that runs on two computers. One
>of these computers has the Windows XP style Theme (green Start button,
>rounded form corners) the other Windows Classic Theme (Gray start button,
>sharp window corners).
>
>My problem is that the same form in my app has a different height for each
>style. The difference is 7 pixels (105 twips).


>Is there a way to check what display style is running on the computer so I
>can compensate for the 7 pixels., or maybe there is another (better) way.


Scalehight should be the only thing your concerned with.

J

Jan Hyde (VB MVP)

--
Why was the broom late?
It over swept!

(Daily Groaner)

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

Bart Steur

2005-03-07, 4:09 pm

Yes, the scaleheight and width are the same in both styles, but I can't set
them at runtime. If I do the scalemode switches to 0 (User-Defined), but I
want Pixels.

Any idea?

B. Steur

"Jan Hyde" <StellaDrinker@REMOVE.ME.uboot.com> wrote in message
news:4lho21h6iarf4m2nliqjh939l4evefd7n1@
4ax.com...
> "Bart Steur" <solnews@xs4all.nl>'s wild thoughts were
> released on Mon, 7 Mar 2005 13:01:20 +0100 bearing the
> following fruit:
>
>
>
> Scalehight should be the only thing your concerned with.
>
> J
>
> Jan Hyde (VB MVP)
>
> --
> Why was the broom late?
> It over swept!
>
> (Daily Groaner)
>
> [Abolish the TV Licence - http://www.tvlicensing.biz/]
>



Jan Hyde

2005-03-07, 4:09 pm

"Bart Steur" <solnews@xs4all.nl>'s wild thoughts were
released on Mon, 7 Mar 2005 13:34:59 +0100 bearing the
following fruit:

>Yes, the scaleheight and width are the same in both styles,
>but I can't set
>them at runtime. If I do the scalemode switches to 0 (User-Defined), but I
>want Pixels.


Dunno, the scalemode doesn't change for me. What happens if
you change the height.

J

>Any idea?
>
>B. Steur
>
>"Jan Hyde" <StellaDrinker@REMOVE.ME.uboot.com> wrote in message
> news:4lho21h6iarf4m2nliqjh939l4evefd7n1@
4ax.com...
>



Jan Hyde (VB MVP)

--
How do you catch a bra?
Set a boobie trap. (Rodney Lee)

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

Bart Steur

2005-03-07, 4:09 pm

Let me explain what I have done.

I've got a form. During design time this form is large (Width 18120 twips,
Height 12870 twips / Scalewidth 1202 pixels, scaleheight 826 pixels,
scalemode=3-pixels). I do this because there are 4 picture box controls
(which are containers for other controls) on this form, which wil overlap
during runtime. During design time it's easier for me to develop with are
large form.

The first thing I do in the Form.load is:

Me.Width = 5535
Me.Height = 6135
For I = 0 to 3
picture(I).Top = 40
picture(I).Left = 24
Next I

6135 is the correct height for the XP style, but for the classic style it
should be 6030.
When I size the form to 6135 in design mode and run the program and swap to
classic mode, everything is OK. When I query the formheight in the debug
mode it's 6030 in classic mode and 6135 in XP mode. Scale height is 377 for
both.

So, one way to solve this is to size the window to proper dimensions before
compiling to an EXE. And ignore the size difference during development.

But I still think there must be a better solution to this.

B.

"Jan Hyde" <StellaDrinker@REMOVE.ME.uboot.com> wrote in message
news:e9ko21dr097ptnbaok2m3n776vn0ae9cpl@
4ax.com...
> "Bart Steur" <solnews@xs4all.nl>'s wild thoughts were
> released on Mon, 7 Mar 2005 13:34:59 +0100 bearing the
> following fruit:
>
>
> Dunno, the scalemode doesn't change for me. What happens if
> you change the height.
>
> J
>
>
>
> Jan Hyde (VB MVP)
>
> --
> How do you catch a bra?
> Set a boobie trap. (Rodney Lee)
>
> [Abolish the TV Licence - http://www.tvlicensing.biz/]
>



Jeff Johnson [MVP: VB]

2005-03-07, 4:09 pm


"Bart Steur" <solnews@xs4all.nl> wrote in message
news:u6FxktxIFHA.3788@tk2msftngp13.phx.gbl...

> The first thing I do in the Form.load is:
>
> Me.Width = 5535
> Me.Height = 6135


And that's your problem. Get rid of the hardcoded values and do MATH against
the ScaleHeight and ScaleWidth to determine how much room you actually have
to work with.


Bart Steur

2005-03-07, 4:09 pm

I would love to use MATH, but how can I get rid of the hardcoded values and
use Scaleheight/width at the same time.

In other words, example please.

B.


"Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message
news:e9v9h6xIFHA.1176@TK2MSFTNGP15.phx.gbl...
>
> "Bart Steur" <solnews@xs4all.nl> wrote in message
> news:u6FxktxIFHA.3788@tk2msftngp13.phx.gbl...
>
>
> And that's your problem. Get rid of the hardcoded values and do MATH
> against the ScaleHeight and ScaleWidth to determine how much room you
> actually have to work with.
>



Jan Hyde

2005-03-07, 4:09 pm

"Bart Steur" <solnews@xs4all.nl>'s wild thoughts were
released on Mon, 7 Mar 2005 14:41:36 +0100 bearing the
following fruit:

>Let me explain what I have done.
>
>I've got a form. During design time this form is large (Width 18120 twips,
>Height 12870 twips / Scalewidth 1202 pixels, scaleheight 826 pixels,
>scalemode=3-pixels). I do this because there are 4 picture box controls
>(which are containers for other controls) on this form, which wil overlap
>during runtime. During design time it's easier for me to develop with are
>large form.
>
>The first thing I do in the Form.load is:
>
> Me.Width = 5535
> Me.Height = 6135
> For I = 0 to 3
> picture(I).Top = 40
> picture(I).Left = 24
> Next I
>
>6135 is the correct height for the XP style, but for the classic style it
>should be 6030.
>When I size the form to 6135 in design mode and run the program and swap to
>classic mode, everything is OK. When I query the formheight in the debug
>mode it's 6030 in classic mode and 6135 in XP mode. Scale height is 377 for
>both.


So if the scaleheight hasn't changed then I can't see where
the problem is.

It seems that you are trying to shrink the form round the
prictureboxes to save you doing it manually. In which case
get rid of the hard coded values. Off the top of my head
something like

Height = Height - ScaleHeight + Picture1.Height

btw, I still don't see why you need to mess about with
scalemode.

J

>So, one way to solve this is to size the window to proper dimensions before
>compiling to an EXE. And ignore the size difference during development.
>
>But I still think there must be a better solution to this.
>
>B.
>
>"Jan Hyde" <StellaDrinker@REMOVE.ME.uboot.com> wrote in message
> news:e9ko21dr097ptnbaok2m3n776vn0ae9cpl@
4ax.com...
>



Jan Hyde (VB MVP)

--
Girls: The best idea that any boy has had to date (Stan Kegal)

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

Ken Halter

2005-03-07, 4:09 pm

"Bart Steur" <solnews@xs4all.nl> wrote in message
news:u2Hs2KyIFHA.3832@TK2MSFTNGP12.phx.gbl...
>I would love to use MATH, but how can I get rid of the hardcoded values and
>use Scaleheight/width at the same time.
>
> In other words, example please.
>
> B.


The part that people keep hinting at, but never clarifying is... you really
can't hard code form sizes. With or without XP themes, the user can change
all kinds of settings that effect the size of borders/scrollbars/etc/etc...
for example, get your app running and use the display applet to set the
'Active Title Bar' to size 50 (or something) and the menu fonts to size 32
or something... if you really want to mess things up, set the system fonts
to Large Fonts instead of Small Fonts. That changes the entire coordinate
system. There's now 12 twips per pixel instead of 15.

'Anyway, the basic code to fill a form with a textbox would look like....
'=====
Private Sub Form_Resize()
If Me.WindowState <> vbMinimized Then
Text1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
End If
End Sub
'=====

'This'll set a forms client area to 400w x 320h, regardless of themes,
titlebar height, etc, etc.
'=====
Private Sub Form_Load()
Dim fWidth As Single
Dim fHeight As Single

fWidth = 400 * Screen.TwipsPerPixelX 'let the system tell you how many
twips are in a pixel
fHeight = 320 * Screen.TwipsPerPixelY

Me.Width = fWidth + (Me.Width - Me.ScaleWidth)
Me.Height = fHeight + (Me.Height - Me.ScaleHeight)

End Sub
'=====



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


Dave

2005-03-07, 4:09 pm

Hi

It doesn't matter which OS or style is running because as someone else
stated the user can change windows settings which will affect this.

All you need to find out is the offset so express the scaleheight in twips,
subtract that from the form height, the difference is the amount to allow
for the top and bottom margins, do a similar thing horizontally to get the
total width of the left & right margins.

Once you have these 2 values you can re-size the form so the workspace is
the same regardless of OS or style which I think is what you want.

Dave.



"Bart Steur" <solnews@xs4all.nl> wrote in message
news:e6WCq1wIFHA.2356@TK2MSFTNGP14.phx.gbl...
> Hello,
>
> I've goto a small problem. I've got an app that runs on two computers. One
> of these computers has the Windows XP style Theme (green Start button,
> rounded form corners) the other Windows Classic Theme (Gray start button,
> sharp window corners).
>
> My problem is that the same form in my app has a different height for each
> style. The difference is 7 pixels (105 twips).
>
> Is there a way to check what display style is running on the computer so I
> can compensate for the 7 pixels., or maybe there is another (better) way.
>
> Thanks,
>
> B Steur
>



Bart Steur

2005-03-07, 4:09 pm

I think we're missing the point here.

Maybe I wasn't clear enough the first time,but after reading all the replies
I've got one thing clear: Do NOT use hardcoded form sizes. This was
especially clearified by Ken.

But the I still have a problem, maybe I am just to lazy, but anyway...
I probably will have to size the form to the right size before
running/testing.

Thanks to you all,

B.



"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:OFV%236qyIFHA.2656@TK2MSFTNGP09.phx.gbl...
> "Bart Steur" <solnews@xs4all.nl> wrote in message
> news:u2Hs2KyIFHA.3832@TK2MSFTNGP12.phx.gbl...
>
> The part that people keep hinting at, but never clarifying is... you
> really can't hard code form sizes. With or without XP themes, the user can
> change all kinds of settings that effect the size of
> borders/scrollbars/etc/etc... for example, get your app running and use
> the display applet to set the 'Active Title Bar' to size 50 (or something)
> and the menu fonts to size 32 or something... if you really want to mess
> things up, set the system fonts to Large Fonts instead of Small Fonts.
> That changes the entire coordinate system. There's now 12 twips per pixel
> instead of 15.
>
> 'Anyway, the basic code to fill a form with a textbox would look like....
> '=====
> Private Sub Form_Resize()
> If Me.WindowState <> vbMinimized Then
> Text1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
> End If
> End Sub
> '=====
>
> 'This'll set a forms client area to 400w x 320h, regardless of themes,
> titlebar height, etc, etc.
> '=====
> Private Sub Form_Load()
> Dim fWidth As Single
> Dim fHeight As Single
>
> fWidth = 400 * Screen.TwipsPerPixelX 'let the system tell you how many
> twips are in a pixel
> fHeight = 320 * Screen.TwipsPerPixelY
>
> Me.Width = fWidth + (Me.Width - Me.ScaleWidth)
> Me.Height = fHeight + (Me.Height - Me.ScaleHeight)
>
> End Sub
> '=====
>
>
>
> --
> Ken Halter - MS-MVP-VB - http://www.vbsight.com
> Please keep all discussions in the groups..
>



Jeff Johnson [MVP: VB]

2005-03-07, 4:09 pm


"Bart Steur" <solnews@xs4all.nl> wrote in message
news:eOlUIIzIFHA.3076@tk2msftngp13.phx.gbl...

>I think we're missing the point here.
>
> Maybe I wasn't clear enough the first time,but after reading all the
> replies I've got one thing clear: Do NOT use hardcoded form sizes. This
> was especially clearified by Ken.
>
> But the I still have a problem, maybe I am just to lazy, but anyway...
> I probably will have to size the form to the right size before
> running/testing.


You're missing the point. You will NEVER be able to set a SINGLE size for
your form at design-time and have it display the way you want it to on ALL
computers. You must CHANGE your form size AT RUN TIME after you have
determined how much space the non-client area of your form is taking up.
Here's the gist of the math I referred to earlier:

In Form_Load, before you make the form visible, put the value of Height -
ScaleHeight into a variable. This tells you how much bigger the non-client
area of the form is than the client area (the area you have to put your
controls in). Then, if you want the client area to be of height x, set the
Height property of the form to x + <the variable you just calculated>.


Russ Holsclaw

2005-03-07, 9:01 pm

<snipping other stuff...>
> 'This'll set a forms client area to 400w x 320h, regardless of themes,
> titlebar height, etc, etc.
> '=====
> Private Sub Form_Load()
> Dim fWidth As Single
> Dim fHeight As Single
>
> fWidth = 400 * Screen.TwipsPerPixelX 'let the system tell you how many
> twips are in a pixel
> fHeight = 320 * Screen.TwipsPerPixelY
>
> Me.Width = fWidth + (Me.Width - Me.ScaleWidth)
> Me.Height = fHeight + (Me.Height - Me.ScaleHeight)
>
> End Sub
> '=====


For the record, Ken, it occurs to me that, if a menu bar is present, the
height of the "non-client-area" will depend on the width of the window.
This is because the menu entries might "wrap" if the window is made more
narrow, thus encroaching further into the remaining client area.

I notice, in your sample code, that you set the width first, then the
height. Do you do this because of the "wrap effect" on the menu bar? Does
this effect take place as soon as the Width property is set and before the
next statement is executed? I haven't tried this myself, but the example
made me wonder about this particular point.

In any case, if it works this way, it's important to point out that the
Width setting has to be done before Height. But, if the "menu wrap"
doesn't take effect right away, one might actually have to insert a
"DoEvents" or something to let it take effect before executing the code to
set Height. (If you happen to have menus, that is.)

I didn't experiment with this myself ... I just thought I'd ask *you*
first. :-)

Russ Holsclaw

2005-03-07, 9:01 pm

I went ahead and tried an experiment:

I created a menubar that would wrap if the form were made any narrower, and
put this code into the Form_Load event...

Private Sub Form_Load()
Dim before As Single
Dim after As Single
before = ScaleHeight
Width = Width - 1440 'make form narrower, to cause menubar wrapping
after = ScaleHeight
MsgBox before & " " & after
End Sub


When I ran it, the values display for "before" and "after" were different,
which means that the menu-wrap takes effect immediately, and Scaleheight is
affected right away.

This means that the code you provided, which sets Width before setting
Height, will work correctly, even if changing the form width affects the
ScaleHeight of the form, due to menu wrapping.

So, did you think of that ahead of time, or just get lucky?

Russ

Ken Halter

2005-03-07, 9:01 pm

"Russ Holsclaw" <russ@holsclaw.nyet> wrote in message
news:OBJFxo1IFHA.588@TK2MSFTNGP15.phx.gbl...
>
> So, did you think of that ahead of time, or just get lucky?
>
> Russ


Just got lucky <g>

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


Russ Holsclaw

2005-03-07, 9:01 pm

>> So, did you think of that ahead of time, or just get lucky?
>
> Just got lucky <g>
>
> --
> Ken Halter - MS-MVP-VB - http://www.vbsight.com
> Please keep all discussions in the groups..



Ah! I should nominate you for the "Honesty in Newsgroup Posting Award", if
there is such a thing. :-)

.... and, of course, we should mention that the initial form height and
width should be such that neither Scaleheight nor ScaleWidth should be
initially zero. Otherwise, the math is wrong ... in other words, you don't
really have a proper determination of the "window-frame overhead" values.
So, don't start out with a "collapsed window" for the initial setting of
Height. In this narrow sense, the code you gave isn't fully generalized.

This should be obvious, of course. But, judging from some of the troubles I
see in the newsgroups, a lot of people blindly copy code that they don't
really understand.

Bart Steur

2005-03-08, 8:59 am

Jeff,

The suggestion/solution you wrote works fine for me. You were right, I was
missing the point here. Sorry.

Thanks,

Bart

"Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message
news:eJcJTb0IFHA.2420@TK2MSFTNGP14.phx.gbl...
>
> "Bart Steur" <solnews@xs4all.nl> wrote in message
> news:eOlUIIzIFHA.3076@tk2msftngp13.phx.gbl...
>
>
> You're missing the point. You will NEVER be able to set a SINGLE size for
> your form at design-time and have it display the way you want it to on ALL
> computers. You must CHANGE your form size AT RUN TIME after you have
> determined how much space the non-client area of your form is taking up.
> Here's the gist of the math I referred to earlier:
>
> In Form_Load, before you make the form visible, put the value of Height -
> ScaleHeight into a variable. This tells you how much bigger the non-client
> area of the form is than the client area (the area you have to put your
> controls in). Then, if you want the client area to be of height x, set the
> Height property of the form to x + <the variable you just calculated>.
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com