Click here to Skip to main content
14,451,179 members
Rate this:
Please Sign up or sign in to 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 23:42pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

Try
myButton.Font = new System.Drawing.Font("Segoe UI", 10.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
myButton.Height = 50;
...
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

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!
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100