I designed a button
How do I inherit the rest of this button?
Does this method of inheritance is true?
mycode :
public class MyButton : Button
{
public MyButton()
: base()
{
// set whatever styling properties needed here
this.ForeColor = Color.Blue;
this.Click += new EventHandler(MyButton_Click);
this.BackColor = Color.Red;
}
void MyButton_Click(object sender, EventArgs e)
{
MessageBox.Show("yes");
}
}
Why not change the background color?
All properties are subject to change
Except the background color
Is this a normal thing
No solution?
You can create a new class, subclass the standard Button, and make your style adjustments in the constructor. Once that's done, rebuild your project, and your new component should appear in the Toolbox in the top section. Use it instead of the standard Button and you should be good to go.
public class MyButton : Button
{
public MyButton() : base()
{
// set whatever styling properties needed here
ForeColor = Color.Red;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With