Click here to Skip to main content
16,012,153 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Team,

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.

What I have tried:

public override Color BackColor
       {
           get { return bColor; }
           set { base.BackColor = value; }
       }

public override void ResetBackColor()
        {
            base.ResetBackColor();
        }

private bool ShouldSerializeBackColor()
        {
            return (!BackColor.Equals(bColor));
        }
I have tried above code, button control default size not override my values.
Posted
Updated 3-Feb-19 22:42pm

Please, refer this: Button Class (System.Windows.Controls) | Microsoft Docs[^] - Customizing the button control[^] section.

Based on above documentation you can:
1) create custom button which inhertis from Button class
See: How to: Inherit from Existing Windows Forms Controls | Microsoft Docs[^]
2) change Style property.

Good luck!
 
Share this answer
 
Try
C#
myButton.Font = new System.Drawing.Font("Segoe UI", 10.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
myButton.Height = 50;
...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900