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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:16:50+00:00 2026-05-28T03:16:50+00:00

I needed to make my own label to hold some value, that is diferent

  • 0

I needed to make my own label to hold some value, that is diferent from the value displayed to user

public class LabelBean : Label {
  private string value;

  public LabelBean(string text = "", string value = ""): base() {
    base.Text = text;
    this.value = value;
  }

  public string Value {
    get { return value; }
    set { this.value = value; }
  }
}

but now id in the form constructor I replace the control with my class

this.lbAttributeType = new LabelBean();

and later after the form is created, but before it is shown I set the text through setter

(this.lbAttributeType as LabelBean).Value = value;
this.lbAttributeType.Text = Transform(value);

but in the form I have always “label1” text… what is wrong with it?
thanks

UPDATE

I added the solution here to find it easier:

public class MyLabel : Label {

    public MyLabel()
      : base() {
    }

    public string Value {
      set {
        this.Text = value;
      }
    }
  }

and the form with Widnows.Forms.Label label1 control

public partial class Form1 : Form {

    public Form1() {
      InitializeComponent();
      this.Controls.Remove(this.label1);
      this.label1 = new MyLabel();
      this.Controls.Add(this.label1);
      (this.label1 as MyLabel).Value = "oh";
    }
  }

the bug was in the Controls.Remove and Controls.Add,
thanks all for their time 🙂

  • 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-28T03:16:51+00:00Added an answer on May 28, 2026 at 3:16 am

    I agree with WoLfulus and Andreas Zoltan and would add a symmetrical functionality to Text if there exists a unambiguous reverse transformation:

    public string Value
    {
        get { return value; }
        set
        {
            if (this.value != value) {
                this.value = value;
                this.Text = Transform(value);
            }
        }
    }
    
    public override string Text
    {
        get { return base.Text; }
        set
        {
            if (base.Text != value) {
                base.Text = value;
                this.value = TransformBack(value);
            }
        }
    }
    

    Note the if checks in order to avoid an endless recursion.


    EDIT:

    Assigning your label to lbAttributeType is not enough. You must remove the old label from the Controls collection before the assignment and re-add it after the assignment.

    this.Controls.Remove(lbAttributeType);  // Remove old label
    this.lbAttributeType = new LabelBean(); 
    this.Controls.Add(lbAttributeType); // Add new label
    

    Your form was still displaying the old label! Why did I not see it earlier?

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

Sidebar

Related Questions

I want to make one project that parse wiki pages and get needed information
I've build my own website from scratch as I needed it to be built
So, I'm trying to make cross-site AJAX request from my own script to the
I needed to make a window smaller than the OS minimum, I decided to
What is needed to make String.IsNullOrEmpty() count whitespace strings as empty? Eg. I want
Is good knowledge of PHP needed to make an installable template for CMS like
I need to build a keystore with all the needed SSL certificates to make
friends. I have a 'make'-like style file needed to be parsed. The grammar is
I am curious as to how applications generate their own data that is used
I am using some code for a coverflow from the website, http://www.inter-fuser.com/2010/01/android-coverflow-widget.html this coverflow

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.