Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8514485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:52:58+00:00 2026-06-11T04:52:58+00:00

I have created a custom Button for use in my WinForms applicationusing the followng

  • 0

I have created a custom Button for use in my WinForms applicationusing the followng little class

public class MyButton : Button
{
    protected override void OnPaint(PaintEventArgs e)
    {
        this.BackColor = Color.ForestGreen;
        base.OnPaint(e);
    }
}

I’m simply looking to make my application cusomizeable so that I only need change button colors (and in due course other controls) in one place, and that change is reflected throughout the whole application.

After creating the custom button using the above code I set about replacing all standard System.Windows.Forms.Buttons() with MyNamespace.MyButton(). However, whilst the new buttons all appear changed on the screen, other controls like text boxes (which I have not modified) simply are not rendered on the screen at all. However if I click and drag a window in my application then all of the missing controls suddenly appear.

I have no idea what is causing this. Can anyone advise me please.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:53:00+00:00Added an answer on June 11, 2026 at 4:53 am

    You shouldn’t be “setting” the backcolor property in a paint event, that can cause a constant refreshing of the screen.

    One option is to try setting the property in the constructor instead:

    public class MyButton : Button
    {
      public MyButton() {
        this.BackColor = Color.ForestGreen;
      }
    }
    

    In order to ignore the serialized BackColor property of the control, you can try to change your button class to something like this:

    public class MyButton : Button {
      private Color myColor = Color.ForestGreen;
    
      public MyButton() {
        base.BackColor = myColor;
      }
    
      [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
      public new Color BackColor {
        get { return myColor; }
        set { // do nothing 
        }
      }
    
    }
    

    This button control will effectively ignore the BackColor property in the designer. If you want to change the color of all of your buttons, you just have to change your myColor value in code and rebuild.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created my own button class called custom_btn. I created it on the
I have created a default style for a Button including a custom ControlTemplate like
I've created custom button derived from a normal .Net button and have added the
I have created one gridview and use custom adapter for that. I added two
I have created one gridview and use custom adapter for that. I added two
I have created a custom button called ModuleUIButton which inherits from UIButton . This
I have created a series of custom jQuery events for use in mobile web
I have created a custom Button as follows. file : buttoncontrol.xml <?xml version=1.0 encoding=utf-8?>
i have created custom components in flex where i have used a button,i want
I have created a custom control in C# ( Overridden methods in Button control

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.