Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Property Calls class
Message
De
08/07/2004 16:02:46
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00922132
Message ID:
00922193
Vues:
12
This message has been marked as the solution to the initial question of the thread.
Shawn,

If you don't need the Set_Color to be a separate method, I'd do it this way (also notice that you need to have two different names, one is the public property and the other is a field (usually private):
public bool HadError
{
	get { return m_HadError;}
	set 
	{
		m_HadError = value;
		if (value)
		{
			this.OrigBackColor = this.BackColor;
			this.BackColor = this.ErrorBackColor;
		}
		else
		{
			this.BackColor = this.OrigBackColor;
		}
	}
}
-or- if you prefer to keep it separate then:
public bool HadError
{
	get { return m_HadError;}
	set {m_HadError = value;
	     this.Set_Color();}
}
Either way is fine.

~~Bonnie


>What i would like to do is if i chnage a value on a custom property, i would like it to call a class that sets an objects backcolor.
>
>So i have a text box which has a property called HadError, when this property is true i would like the text box to turn red automatically.
>
>I have defined a property as follows where would i add the code to call the class that sets the color?
>
>
>private Color ErrorBackColor = Color.DarkRed;
>private Color OrigBackColor;
>
>[Description("If the TextBox Had an Error. Set by Business Object"),
>Category(""),
>DefaultValue(false)]
>public bool HadError
>{
>	get { return HadError;}
>	set {HadError = value;}
>}
>
>
>private void Set_Color()
>{
>	if (this.HadError)
>	{
>		this.OrigBackColor = this.BackColor;
>		this.BackColor = this.ErrorBackColor;
>	}
>	else
>	{
>		this.BackColor = this.OrigBackColor;
>	}
>}
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform