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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:47:58+00:00 2026-05-19T13:47:58+00:00

I am trying to add a System.Windows.Forms.Control to a given forms control collection. I

  • 0

I am trying to add a System.Windows.Forms.Control to a given forms control collection. I do this by creating a private field of type control and then instantiating this field to a new instance of System.Windows.Forms.Control in the constructor.

At runtime I am trying to change the type of the _placeholder variable to a TextBox, by doing something like in the following code example. So basically I am trying to have a placeholder of type Control and change it to another control like a TextBox or Label at runtime. My issue is that nothing shows up on my form? Any insight would be appreciated.

public class MyForm : Form
{
  System.Windows.Forms.Control _placeholder = null;

  public MyForm()
  {
    _placeholder = new System.Windows.Forms.Control();
    this.Controls.Add(_placeholder);

    ChangeToTextBox();
  }

  public void ChangeToTextBox()
  {
    _placeholder = new TextBox();
  }
}
  • 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-19T13:47:59+00:00Added an answer on May 19, 2026 at 1:47 pm

    This won’t work, as written, because the original placeholder is still the reference added to the controls. You could fix it by doing:

    public void ChangeToTextBox()
    {
      this.Controls.Remove(_placeholder); // Remove old
      _placeholder = new TextBox();
      this.Controls.Add(_placeholder); // Add new
    }
    

    That being said, if this is going to go into the same location on your form, you might want to consider putting a Panel there instead, and just adding the TextBox to the Panel. This will prevent the need to remove existing controls since it’s just adding one in.

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

Sidebar

Related Questions

I'm trying to put a plain image on a System.Windows.Forms.StatusStrip control (Visual Studio 2008,
I'm trying to use a System.Windows.Forms.DataGrid control in my Compact Framework 3.5 Window Mobile
I have been trying to find out how to bind data to a System.Windows.Forms.DomainUpDown()
I'm trying add a tab to my web page that looks like this: Using
I'm trying to add a control(Label) inside of a panel. Please see the code:
I have a custom user control that fires an exception when trying to add
I am trying to use SMO in a Windows Forms application to restore a
Trying to add an onclick handler to my tabs, and can't seem to get
trying to add an ExpiresDefault ExpiresByType to content on my website so that way
I was trying to add a favicon to a website earlier and looked for

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.