Visual Studio and Custom Control colors

K

kevin cline

I have code like this:

public class MyControl: Control
{
public MyControl()
{
this.BackColor = MyStandardBackColor;
}

public bool ShouldSerializeBackColor()
{
return BackColor != MyStandardBackColor;
}

public void ResetBackColor()
{
BackColor = MyStandardBackColor;
}
}

However, I have found that the VS2005 designer sets the control
backcolor to the Microsoft gray after MyControl is constructed. Is
there a way to prevent this from happening, so that my developers do
not have to go and manually reset the BackColor property of every
control?

Is there anyone at Microsoft who might be interested in this problem.
My bug reports are never acknowledged.
 
R

Rocky

You need to override the BackColor Property and apply the DefaultValue
attribute. In the constructor set the this.BackColor = MyStandardBackColor.
Forget what I said about not setting the color in the constructor, my bad.
 
K

kevin cline

Rocky said:
You need to override the BackColor Property and apply the DefaultValue
attribute. In the constructor set the this.BackColor = MyStandardBackColor.
Forget what I said about not setting the color in the constructor, my bad.

There is no way to apply the DefaultValue attribute, because the
default back color is computed from a configuration file.
 

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