override BackColor

P

perspolis

HI
I created a user control and place some control on it.
I need when I change BackColor of user control,Back Color of other controls
also change..
I used foloowing code:
public override Color BackColor
{
get{return this.BackColor;}
set{
this.BackColor=value;
this.button1.BackColor=value;
}
}
but this code cause an exception of type StackOverFlow..
?????
 
E

Eyal Safran

perspolis said:
HI
I created a user control and place some control on it.
I need when I change BackColor of user control,Back Color of other controls
also change..
I used foloowing code:
public override Color BackColor
{
get{return this.BackColor;}
set{
this.BackColor=value;
this.button1.BackColor=value;
}
}
but this code cause an exception of type StackOverFlow..
?????

Hi,

Its simple: you should use base.BackColor = value not this.BackColor =
value...


When calling this.BackColor = value, you are calling yourself again...

Eyal.
 
E

Eyal Safran

perspolis said:
HI
I created a user control and place some control on it.
I need when I change BackColor of user control,Back Color of other controls
also change..
I used foloowing code:
public override Color BackColor
{
get{return this.BackColor;}
set{
this.BackColor=value;
this.button1.BackColor=value;
}
}
but this code cause an exception of type StackOverFlow..
?????

In order to avoid StackOverflow:

public override Color BackColor
{
get
{
return base.BackColor;
}
set
{
base.BackColor = value;
this.button1.BackColor=value;
}
}

Eyal.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top