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?
LBL.width = ( UserControl.ScaleWidth-2)*Screen.TWIPSPERPIXELX
instead of
LBL.width = UserControl.ScaleWidth-2*Screen.TWIPSPERPIXELX
?
ScaleMode is something you don't appear to be catering for.
--
Jan Hyde (VB MVP)
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.
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.
>> 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.
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.
>> 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.