Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

usercontrol's width = 0

0 views
Skip to first unread message

Klaus Kleiner

unread,
Oct 8, 2008, 8:42:55 AM10/8/08
to
I made a simple panel usercontrol, only a rectangle
containing one label but with the capability of fore- and
background colors, a very simple control which could rarely
be simpler. No big action.

When I use this control in a larger project, sometimes - and
only sometimes - I get an error at saving or compiling the
project because of usercontrol.scalewidth (and also
usercontrol.width) is zero and therefore the label's width
turns negative when computed as LBL.width =
UserControl.ScaleWidth-2*Screen.TWIPSPERPIXELX . In the host
application there is no resizing done which could lead to
widh=0, f.e. due to an error. According to that the IDE
shows no calling function when breaking down, only the
resize event where the width calculation is placed.

But why else can a usercontrol shrink to zero, and why
doesn't it occur only sometimes?

Patrick Weidener

unread,
Oct 8, 2008, 9:05:54 AM10/8/08
to
Maybe you should rather say

LBL.width = ( UserControl.ScaleWidth-2)*Screen.TWIPSPERPIXELX
instead of
LBL.width = UserControl.ScaleWidth-2*Screen.TWIPSPERPIXELX

?

Jan Hyde (VB MVP)

unread,
Oct 8, 2008, 10:56:41 AM10/8/08
to
"Klaus Kleiner" <kkno...@sofort-mail.de>'s wild thoughts
were released on Wed, 8 Oct 2008 14:42:55 +0200 bearing the
following fruit:

ScaleMode is something you don't appear to be catering for.


--
Jan Hyde (VB MVP)

https://mvp.support.microsoft.com/profile/Jan.Hyde

Klaus Kleiner

unread,
Oct 10, 2008, 1:00:16 PM10/10/08
to
> ScaleMode is something you don't appear to be catering
> for.

Hmm, I'm not sure what you mean.

AFAIK ScaleWidth and ScaleHeight return the net available
space, width or height minus space needed to draw the frame.

If ScaleWidth goes to zero obviously control's width also
must be set to zero. As it is not set to zero by code I
asked what else could be the reason for it.

Indeed, as I already wrote before, using the width property
showed that this property was also zero so it shouldn't be a
question of ScaleMode. ScaleMode was unchanged at its
default mode.

Klaus Kleiner

unread,
Oct 10, 2008, 1:03:29 PM10/10/08
to
> LBL.width = (
> UserControl.ScaleWidth-2)*Screen.TWIPSPERPIXELX
> instead of
> LBL.width =
> UserControl.ScaleWidth-2*Screen.TWIPSPERPIXELX

Thanks, but I shouldn't. I want to subtract exactly two
pixels in width what means 2*TWIPSPERPIXELX in twips.
The problem is not that width was too small to hold four
pixels, it was large enough but temporarily returning zero.

Jan Hyde (VB MVP)

unread,
Oct 13, 2008, 7:42:11 AM10/13/08
to
"Klaus Kleiner" <kkno...@sofort-mail.de>'s wild thoughts
were released on Fri, 10 Oct 2008 19:00:16 +0200 bearing the
following fruit:

>> ScaleMode is something you don't appear to be catering

>> for.
>
> Hmm, I'm not sure what you mean.
>
>AFAIK ScaleWidth and ScaleHeight return the net available
>space, width or height minus space needed to draw the frame.

Yea, and what are they returning? Twips, pixels, somthing
else? Scalemode would tell you.

>If ScaleWidth goes to zero obviously control's width also
>must be set to zero. As it is not set to zero by code I
>asked what else could be the reason for it.
>
>Indeed, as I already wrote before, using the width property
>showed that this property was also zero so it shouldn't be a
>question of ScaleMode. ScaleMode was unchanged at its
>default mode.

The other explination is a bug in the usercontrol.

Klaus Kleiner

unread,
Oct 14, 2008, 1:00:57 PM10/14/08
to
> The other explination is a bug in the usercontrol.

Hmm, I wrote "very simple control which could rarely be
simpler. No big action."
Really, a usercontrol rarely can have less code than this
one :-)

But in the last days I found that some code of usercontrols
is executed already at saving the code in in IDE, or showing
the control's surface in the parent form, probably doing
some code when painting or resizing, and I suppose that
under some conditions this code can be run while the width
property still returns zero. I can't figure out that better
because in the IDE I only see fired event without any
'parent' action which fires.

Jan Hyde (VB MVP)

unread,
Oct 15, 2008, 4:44:56 AM10/15/08
to
"Klaus Kleiner" <kkno...@sofort-mail.de>'s wild thoughts
were released on Tue, 14 Oct 2008 19:00:57 +0200 bearing the
following fruit:

>> The other explination is a bug in the usercontrol.

Post the whole code for your simple user control, and then
outline the steps to recreate the issue.

0 new messages