-2

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.

Richard
  • 106,783
  • 21
  • 203
  • 265

1 Answers1

0

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

  • If try above code using constructor then properties which we are used, those properties shows in .designer.cs file too.I want to restrict that too. pls if we using override only we will restrict .designer.cs file. but still not get expected result .. – Mohankumar Somasundaram Feb 04 '19 at 06:35