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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:56:00+00:00 2026-05-13T08:56:00+00:00

What ways can you dynamically create controls in C#? This was objects at first

  • 0

What ways can you dynamically create controls in C#?

This was objects at first but it would have been more precise to say controls. My terminology was messed up. Thanks Joel.

Edit{
Controls that are created during runtime. And are able to be accessed and edited by the program.
Does this help?
}

I like the idea of Dynamic creation and was wondering what ways there were to do this.

Please only one per answer, I would like to see how people rank them.

eg

private Label _lblCLastName = new Label(); 
private static List<ChildrenPanel> _ListCP = new List<ChildrenPanel>(); 

public void CreatePanel(Panel Container) 
{ 
    // Created Controls
    #region Controls 
    _pnlStudent.Controls.Add(_lblCLastName); 
    //  
    // lblCLastName 
    //  
    _lblCLastName.AutoSize = true; 
    _lblCLastName.Location = new System.Drawing.Point(6, 32); 
    _lblCLastName.Name = "lblCLastName"; 
    _lblCLastName.Size = new System.Drawing.Size(58, 13); 
    _lblCLastName.TabIndex = 10; 
    _lblCLastName.Text = "Last Name"; 

    // Adds controls to selected forms panel 
    Container.Controls.Add(_pnlStudent); 
    // Creates a list of created panels inside the class 
    // So I can access user input 
    ListCP.Add(this); 

} 

This is a code snippet from something that is close to what I’m talking about. I made another post but didn’t quite post the question right. I will be deleting it but atm it is still viewable.

If there are still problems please be constructive I don’t mind negitive input as long as it’s helpful.

Edit:
I was able to get some answers I was looking for. Thank you to everyone who replied. I will close this when I am able too. If someone else can close it that would be appreciated.

  • 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-13T08:56:00+00:00Added an answer on May 13, 2026 at 8:56 am

    Creating GUI objects dynamically can be extremely useful, however, it can also be a nightmare for maintenance.

    A good rule of thumb is to limit the amount of GUI object you dynamically create.

    One situation where you may actually want to use a dynamically created GUI object is when you don’t know the amount or count of objects you need. For example, one label for each row in a result set (even then you may consider a DataGrid or GridView type object).

    This works for both WinForms and ASP.NET. Just be sure to document your code correctly.

    My advice would be to stick with the Visual Designer for simpler forms and only create and add objects dynamically when it’s absolutely necessary.

    (FWIW, the code snippet you posted could probably be simplified and/or refactored as it seems to be going in the wrong direction.)

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

Sidebar

Ask A Question

Stats

  • Questions 274k
  • Answers 274k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer DateTime.strptime allows you to specify the format and convert a… May 13, 2026 at 2:27 pm
  • Editorial Team
    Editorial Team added an answer You should check whether or not the textField the label… May 13, 2026 at 2:27 pm
  • Editorial Team
    Editorial Team added an answer You can use GetType() method to get the actual type… May 13, 2026 at 2:27 pm

Related Questions

In one of my projects I need to build an ASP.NET page and some
What are the different ways you can control/read the Scrollbar in a web browser
NOTE: I am not exactly sure how to title or tag this question, so
.NET offers a generic list container whose performance is almost identical (see Performance of
In short: Is there an existing open-source Python interface for the Apache scoreboard IPC

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.