How to override button properies in C#(font, height, width, backcolor)

126 views Asked by At

How to Override my controls using C#?

Need to set button property like

Font(Name => Segoe UI, style => Regular, size => 10), height => 50px, width => 250px, back color => green

by default.

How to use override method for respected button properties.

Note: I am going to use windows control library controls, to my projects. Thanks in advance.

1

There are 1 answers

1
Hitesh Savaliya On

you can make your custom control for overriding with your default properties.

Sample button code for custom button:

using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace DemoControls
{
    [ToolboxItem(true)]

    public class SimpleButton : Button
    {
        public SimpleButton()
        {
            Font = new Font("Segoe UI", 10, FontStyle.Regular);
            Height = 50;
            BackColor = DefaultBackColor;
        }
    }
}

It will show control in your toolbox when you build your project then you have to use this SimpleButton in your project where you want