Ryan,
The only way that this will get called is if you have a value that is
different from the default value. You need to do this:
private bool normalMode = false;
[DefaultValue(fa lse)];
public bool NormalMode
{
get
{
return this.normalMode ;
}
set
{
SetAsNormal(val ue);
this.normalMode = value;
}
}
Then, the designer will set the value for your component in
InitializeCompo nent method when you set a value to something OTHER than the
default value. If it is NOT the default value, then it ^will^ not and
^should^ not be set.
If you have a need for SetAsNormal(val ue) to be called, then in your
constructor, you should call SetAsNormal(nor malMode).
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard. caspershouse.co m
"Ryan Liu" <ad********@onl ine.sh.cnwrote in message
news:ec******** ******@TK2MSFTN GP03.phx.gbl...
Hi,
What is the best practise to sove this problem:
property with defalut value will not be called in auto-generated code
?
for example
there is a property in a user control
private bool normalMode = false;
public bool NormalMode
{
get
{
return this.normalMode ;
}
set
{
SetAsNormal(val ue);
this.normalMode = value;
}
If I put this user control in a form, in forms InitializeCompo nent(),
there
is no code like
userControl1.No rmalMode = false;
so line like SetAsNormal(val ue); will not be called.
What is the best way to solve this? And how to make a property only
visible
at design time?
Thanks a lot!
Ryan Liu