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

  • SEARCH
  • Home
  • 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 7683867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:53:41+00:00 2026-05-31T18:53:41+00:00

I have a library. In the library, I have a button with a Green

  • 0

I have a library. In the library, I have a button with a Green background color and Text as Go Green.

Now I made a winform project and dragged my Go green button in the form. On running the application, I noticed that the button color is changing to green but text is displayed as button1 (name of the class library).

My library looks like:

public class button : Button
{
    public Seats()
    {
        button.BackColor = Color.Green;
        button.Text = "Go Green";
    }
}

I discovered that it is happening because InitializeComponent() method is called in the constructor of the form. And in designer.cs,

button.Text = "button1";

is called. How can I avoid that to happen. I want my text to be visible from my class library.

Note: When I manually removed the above code from the designer.cs, everything was working fine.

  • 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-05-31T18:53:42+00:00Added an answer on May 31, 2026 at 6:53 pm

    Easiest way – override button’s Text property and make it hidden to designer serialization:

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public override string Text
    {
        get { return base.Text; }
        set { base.Text = value; }
    }
    

    Designer will add default button name, but when you build application, your text will be shown.

    UPDATE: Another (harder) way – provide to designer default property value for your button. In this case you need reference System.Design.dll which is available only for full version of .net framework (not client profile version).

    First: create control designer for your button

    public class GoGreenButtonDesigner : System.Windows.Forms.Design.ControlDesigner
    {
        public override void OnSetComponentDefaults()
        {
            base.OnSetComponentDefaults();
            Control.Text = "Go Green";
        }
    }
    

    Last: add Designer attribute to your custom button class

    [Designer(typeof(GoGreenButtonDesigner))]
    public class GoGreenButton : Button
    {
       //...
    }
    

    That’s it. Now when you drag button to form, it will have default text “Go Green” without any additional compilations.

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

Sidebar

Related Questions

I'm making a custom button (Winforms Control Library) and have the code below so
i have view controller which contains a button which show the image library ,if
I have gdata library install on my ArchLinux, and a simple application which imports
We have a Library Project that we use for all our central reused code
I have an application with only one button. When user clicks the button, a
I have a project in Eclipse that I use as a library (I export
I currently have a wcf service library project that includes my service contract &
I have the zxing library imported into my project and the scanner works like
I have a textbox and button in an aspx page. I enter some text
I have to use openFlow library in my iphone project.If anyone used the openFlow

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.