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 8302681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:20:47+00:00 2026-06-08T17:20:47+00:00

I have a question regarding User Controls created with Visual Studio 2010. Specifically, I

  • 0

I have a question regarding User Controls created with Visual Studio 2010.

Specifically, I have created a simple User Control extending the default Label .Net control. Using the Designer, I specified the BackColor of my User Control to “White” (note that my User Control does have an area of its own not occupied by any other control). After building the project, I used my control on a form of a second project under the same solution by dragging it from the toolbox.

After the placement of the control, I modified the very same property of my User Control and turned BackColor to “Red”. I recompiled the entire solution (with project dependencies checked – user control project first and the dependent second project last). Subsequently, I created a second instance of my User Control on the form (by dragging it from the toolbox). Although this second instance appears with “Red” background as expected, the first instance persists with the “White” BackColor.

This is highly non-intuitive to me and I am wondering why? I expect ALL controls to adopt any changes made to the base class when the changes affect properties not overriden after their placement on the form. The only conclusion I managed to derive is that it has to do with VS generating the “designer.vb” code for the first instance of the control and NEVER regenerating it afterwards, even though the base user control has been altered and recompiled.

Any ideas ?

UPDATE: Thank you all for your answers! I would like to point out that setting the BackColor property was merely an example for illustrating my point. It appears to me that even if no properties at all are defined for my custom control during design time, VS generates a standard set of properties in the code behind( in addition to any explicit properties defined by the developer). Therefore, omitting the explicit specification of properties does not always tackle the problem (the default VS mechanism of setting properties in the designer.vb file). I believe the only way to address the issue once and for all, is to set property initialization code inside the control’s New or Load method; not always a practical solution when a lot of initialization needs to be performed!

  • 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-08T17:20:48+00:00Added an answer on June 8, 2026 at 5:20 pm

    This goes wrong because you haven’t told the designer what the default value for the property is. So when you drop your custom label on a form, the designer generates this kind of code in the form’s Designer.cs file:

            this.myLabel1.AutoSize = true;
            this.myLabel1.BackColor = System.Drawing.Color.Red;         // <=== Here !
            this.myLabel1.Location = new System.Drawing.Point(19, 22);
            this.myLabel1.Name = "myLabel1";
            this.myLabel1.Size = new System.Drawing.Size(52, 13);
            this.myLabel1.TabIndex = 0;
            this.myLabel1.Text = "myLabel1";
    

    The marked statement ruins it. When you now change the default in the control class, any control that you’ve already dropped on any form is not going to change to that default color, the designer code overrides it.

    You’ll need to use the [DefaultValue] attribute to tell the designer about your default. Like this:

    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    
    class MyLabel : Label {
        public MyLabel() {
            this.BackColor = Color.Red;
        }
        [DefaultValue(typeof(Color), "Red")]
        public override Color BackColor {
            get { return base.BackColor; }
            set { base.BackColor = value; }
        }
    }
    

    Now the designer will omit the assignment and any change you make inside the control will be effective. The attribute syntax is clumsy, unfortunately you need to use a string.

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

Sidebar

Related Questions

I am not an experienced iPhone user, so I have a question regarding to
I have a question regarding Tab Item Content. How do I specifically choose what
I am a newbie user of Frama-C and have a few questions regarding assertions
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have question regarding the use of function parameters. In the past I have
I have question regarding disabling browser caching. I have already found few solutions, and
i have a question regarding the AsyncTask class in android, and why it is
I have a question regarding applying a RTRIM on a ASP:Hyperlink statement. The code
I have a question regarding the proper way to modify a php DateTime object.
I have a question regarding the best practise of handling formated text when using

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.