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?

Re: usercontrol's width = 0 by Patrick

Patrick
Wed Oct 08 08:05:54 CDT 2008

Maybe you should rather say

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

?

Re: usercontrol's width = 0 by Jan

Jan
Wed Oct 08 09:56:39 CDT 2008

"Klaus Kleiner" <kknospam@sofort-mail.de>'s wild thoughts
were released on Wed, 8 Oct 2008 14:42:55 +0200 bearing the
following fruit:

>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?

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


--
Jan Hyde (VB MVP)

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

Re: usercontrol's width = 0 by Klaus

Klaus
Fri Oct 10 12:00:16 CDT 2008

> 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.


Re: usercontrol's width = 0 by Klaus

Klaus
Fri Oct 10 12:03:29 CDT 2008

> 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.


Re: usercontrol's width = 0 by Jan

Jan
Mon Oct 13 06:42:11 CDT 2008

"Klaus Kleiner" <kknospam@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.
--
Jan Hyde (VB MVP)

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

Re: usercontrol's width = 0 by Klaus

Klaus
Tue Oct 14 12:00:57 CDT 2008

> 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.


Re: usercontrol's width = 0 by Jan

Jan
Wed Oct 15 03:45:14 CDT 2008

"Klaus Kleiner" <kknospam@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.
>
>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.

Post the whole code for your simple user control, and then
outline the steps to recreate the issue.
--
Jan Hyde (VB MVP)

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