S
steve
I've created a button class (MyButton) that derives from
System.Windows.Forms.Button.
In the constructor, I set the ForeColor and BackColor properties of the
button with a static color like this:
this.ForeColor = StaticForeColor
this.BackColor = StaticBackColor
It's really important that the Designer Generated Code doesn't set the
ForeColor and BackColor at design time. Is there a way to prevent the
Designer Generated Code from doing this?
Let me explain why. My idea behind creating a class this way, is so I can
set the colors of the button for the whole class dynamically in my project
when the project is loaded like this:
MyButton.StaticForeColor = Color.Blue;
The problem is, the Designer Generated Code automatically puts in lines
like this:
this.MyButton1 = new MyNameSpace.MyButton();
//
// MyButton1
//
...
this.btnBuildingView.BackColor = System.Drawing.Color.Black;
this.btnBuildingView.ForeColor =
System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(102)),
((System.Byte)(255)));
And even though the button class (MyButton) the StaticForeColor is not
initialized, it's just:
public static Color StaticForeColor;
The Designer Still generates code for the ForeColor and BackColor in the
//
// MyButton1
//
section because I set those values in the constructor.
So, during runtime, no matter what I change the StaticForeColor to, the
button will have it's ForeColor set to the StaticForeColor but immediately
afterwards, it will be reset to:
this.btnBuildingView.ForeColor =
System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(102)),
((System.Byte)(255)));
or something like it.
Thanks
Steve
System.Windows.Forms.Button.
In the constructor, I set the ForeColor and BackColor properties of the
button with a static color like this:
this.ForeColor = StaticForeColor
this.BackColor = StaticBackColor
It's really important that the Designer Generated Code doesn't set the
ForeColor and BackColor at design time. Is there a way to prevent the
Designer Generated Code from doing this?
Let me explain why. My idea behind creating a class this way, is so I can
set the colors of the button for the whole class dynamically in my project
when the project is loaded like this:
MyButton.StaticForeColor = Color.Blue;
The problem is, the Designer Generated Code automatically puts in lines
like this:
this.MyButton1 = new MyNameSpace.MyButton();
//
// MyButton1
//
...
this.btnBuildingView.BackColor = System.Drawing.Color.Black;
this.btnBuildingView.ForeColor =
System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(102)),
((System.Byte)(255)));
And even though the button class (MyButton) the StaticForeColor is not
initialized, it's just:
public static Color StaticForeColor;
The Designer Still generates code for the ForeColor and BackColor in the
//
// MyButton1
//
section because I set those values in the constructor.
So, during runtime, no matter what I change the StaticForeColor to, the
button will have it's ForeColor set to the StaticForeColor but immediately
afterwards, it will be reset to:
this.btnBuildingView.ForeColor =
System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(102)),
((System.Byte)(255)));
or something like it.
Thanks
Steve