C# How to create a label in run time, and place it on a particular panel

Posted on 2007-08-09
Last Modified: 2008-02-01
How to create a label in run time, and place it on a particular panel
Question by:amielDorel
    LVL 2

    Expert Comment

    Label myLabel = new Label();
    myLabel.Text = "enter text here";
    Panel myPanel = new Panel();

    You can also control other label properties as location, dock, anchor, etc.
    LVL 2

    Accepted Solution

    Please correct the last line of code above.
    instead of myPanel.Controls.Add(myPanel); put myPanel.Controls.Add(myLabel );

    If the Panel hasn't been added to your Form yet, you can also do it by myForm.Controls.Add(myPanel);

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now