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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:00:25+00:00 2026-05-26T20:00:25+00:00

Here’s the setup: I’ve created a user control MyUserControl. On this control is a

  • 0

Here’s the setup: I’ve created a user control MyUserControl. On this control is a simple label. When I drop a new instance of this control on a form, I would like the label to be the name of the control. For example, if this is the first instance of the control, VStudio automatically sets the name of it to be “myUserControl1”. I would simply like the label to read “myUserControl1”. If this is the fifth control, VStudio will name it myUserControl5. I would like the label to change accordingly… but only if it hasn’t already been set. Once I set it to read “The Label”, it should be left alone.

I thought it would be easy. In the constructor, set label1.Text = this.Name. But then I realized, at instantiation this.Name is simply MyUserControl. It hasn’t been named yet by VisualStudio and the CONTAINING InitializeComponent() method.

Ah! I’ll just override the “Name” field. When it gets set, check for DesignMode and update the label!… but I can’t override the name. It’s not virtual or abstract. I can use “new” to force it, but then, it never fires, thus defeating the purpose.

Which event can I use to denote when the designer has named the control? I know that the redmond folks do it all the time when they drop a control on the form, so it’s very possible. I’m actually quite stumped by this little riddle.

  • 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-26T20:00:26+00:00Added an answer on May 26, 2026 at 8:00 pm

    So, here’s the final answer:

    Per Hans’ suggestion, it did require a ControlDesigner. I created a simple designer that would interface with some internal properties, and I did get it to work. Here’s the catch, though: It’s a bit of a hack. There doesn’t seem to be a single field that has the value I’m looking for, so I had to do a .ToString() on an object, then parse out the first section. I figured that’s about as clean as it is going to get.

    public class MyControlDesigner : ControlDesigner
    {
        public MyControlDesigner()
        {
        }
    
    
        public override void InitializeNewComponent(IDictionary defaultValues)
        {
            base.InitializeNewComponent(defaultValues);
    
            MyControl control1 = this.Component as MyControl;
            control1.LabelText = control1.ToString().Split(" ".ToCharArray())[0];
        }
    }
    

    Then at the top of MyControl, I simply added a new attribute:

    [DesignerAttribute(typeof(MyControlDesigner))]
    public partial class MyControl : UserControl
    {
        ...
    
        // Using the property "Text" Causes Visual Studio to crash!!!
        public string LabelText
        {
            get { return label1.Text; }
            set { label1.Text = value; }
        }
    
        ...
    }
    

    As you can see, it wasn’t very complicated, but it is a bit hack-ish. The control locked up the IDE when I tried to override “Text”. Not sure why, but when I called it “LabelText”, it worked perfectly.

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

Sidebar

Related Questions

Here is my question. I am having this simple menu. <div id=menu> <ul> <li>
Here's the problem....I have three components...A Page that contains a User Control and a
Here's a problem I ran into recently. I have attributes strings of the form
Here is my code, which takes two version identifiers in the form 1, 5,
Here's a coding problem for those that like this kind of thing. Let's see
Here we go again, the old argument still arises... Would we better have a
Here is what I have: Dim cmsManager As New Telerik.Cms.CmsManager() Dim currentNode As Telerik.Cms.Web.CmsSiteMapNode
Here's my problem I have this javascript if (exchRate != ) { function roundthecon()
Here is what I want to do. Use this HTML line and have the
here is how i call the following function: List<decimal> numbers = new List<decimal>(); numbers.Add(210m);

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.