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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:02:34+00:00 2026-06-12T04:02:34+00:00

I’m working on a program that is supposed to use with multiple users. I’m

  • 0

I’m working on a program that is supposed to use with multiple users. I’m getting the users from a database. So far so good…

I’m dynamically adding a panel to the form, which would hold some data. I’m using this piece of code to achieve that:

string panel_name = "email_in_" + user_credentials[counter_snel][0];
Panel new_user_panel = new Panel();
new_user_panel.AutoSize = true;
new_user_panel.Dock = System.Windows.Forms.DockStyle.Fill;
new_user_panel.Location = new System.Drawing.Point(0, 0);
new_user_panel.Name = panel_name;
new_user_panel.Visible = false;

Label new_item = new Label();
new_item.AutoSize = true;
new_item.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
string new_item_text = string.Format("{0,0}\n{1,0}\n{2,0}", user_credentials[counter_snel][1], user_credentials[counter_snel][2],user_credentials[counter_snel][9]);
new_item.Text = new_item_text;
splitContainer2.panel_name.Controls.Add(new_item);

as you will probably notice, this line of code is not working:

splitContainer2.panel_name.Controls.Add(new_item);

How can I achieve this, so when I want to make panel email_in_1 visible, I can use that, and make email_in_8 not visible?

### EDIT 1 ###

the code now looks like this:

string panel_name = "email_in_" + user_credentials[counter_snel][0];
Panel new_user_panel = new Panel();
new_user_panel.AutoSize = true;
new_user_panel.Dock = System.Windows.Forms.DockStyle.Fill;
new_user_panel.Location = new System.Drawing.Point(0, 0);
new_user_panel.Name = panel_name;
new_user_panel.Visible = true;
user_email_in_panels.Add(new_user_panel);
splitContainer2.Panel1.Controls.Add(new_user_panel);

Label new_item = new Label();
new_item.AutoSize = true;
new_item.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
string new_item_text = string.Format("{0,0}\n{1,0}\n{2,0}", user_credentials[counter_snel][1], user_credentials[counter_snel][2],user_credentials[counter_snel][9]);
new_item.Text = new_item_text;
int aantal_panels = 0;
foreach (Panel panel in user_email_in_panels) {
        aantal_panels++;
}
int counter_1 = 0;
foreach (Panel panel in user_email_in_panels) {
        if(counter_1 == (aantal_panels -1)){
               MessageBox.Show("We are here");
               panel.Controls.Add(new_item);
               splitContainer1.Panel1.Controls.Add(panel);
        }
        counter_1++;
}

But somehow, i don’t see any labels shown in the form… am i missing something? The messsagebox with the text We are Here is shown, so it come’s to the add statement….

and i’ve got an another question besides my first question. My question is, how can i make the counter of the list better?

### Edit for Sean Vaughn

i’ve updated it to this:

public class MyPanelClass {
    public string Name {
        get;
        set;
    }

    public bool Visible {
        get;
        set;
    }

    public string YourLabelsText {
        get;
        set;
    }
}

Label new_item = new Label();
new_item.AutoSize = true;
new_item.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
string new_item_text = string.Format("{0,0}\n{1,0}\n{2,0}", user_credentials[counter_snel][1], user_credentials[counter_snel][2], user_credentials[counter_snel][9]);
new_item.Text = new_item_text;

Panel base_panel = new Panel();    //this is your base panel, you don't need to add this line of code because Visual Studio will do that for you.
List<MyPanelClass> myPanelList = new List<MyPanelClass>();    //this will keep records of all of your panels.

MyPanelClass panel_name = new MyPanelClass();
panel_name.Name = "email_in_" + user_credentials[counter_snel][0]; ;
panel_name.Visible = true;
panel_name.YourLabelsText = string.Format("{0,0}\n{1,0}\n{2,0}", user_credentials[counter_snel][1], user_credentials[counter_snel][2], user_credentials[counter_snel][9]);

//Now add the new created panel to the list.
myPanelList.Add(panel_name);

base_panel.Name = myPanelList[counter_snel].Name;
base_panel.Visible = myPanelList[counter_snel].Visible; //You probably don't need this because base_panel will always be visible
new_item.Text = myPanelList[counter_snel].YourLabelsText;

But i still doesn’t see anything…
Does it matter that it execudes in an public void??? i don’t think so, but it want to elliminate all the possibilities…

  • 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-06-12T04:02:35+00:00Added an answer on June 12, 2026 at 4:02 am

    Use a List that will keep track of all the panels.

    List<Panel> myPanels = new List<Panel>();
    

    Whenever you need to add a panel, do this:

    mypanels.Add(yourPanel);
    

    Now, for the other problem, create a function like this:

    private void HideAllOtherPanels(List<Panel> panelList, Int index /*the index of the panel you want to show*/)
    {
        foreach(Panel panel in panelList)
            if(panel.Visible) panel.Hide();
    
        panelList[index].Show();
    }
    

    I see you are creating a lot of new panels. My advice, don’t do that, you’re giving a lot of load to the system.

    Instead make a class.

    public class MyPanelClass
    {
        public string Name
        {
            get; set;
        }
    
        public bool Visible
        {
            get; set;
        }
    
        public string YourLabelsText
        {
            get; set;
        }
    }
    

    After creating the class, create a base_panel on your form that will change it’s contents based on the your intentions.
    And then, all you need to do is change the panel’s content rather than creating a new Panel. Store the other panels data in a List<MyPanelClass>.

    So you’ll be doing this:

    Panel base_panel = new Panel();    //this is your base panel, you don't need to add this line of code because Visual Studio will do that for you.
    List<MyPanelClass> myPanelList = new List<MyPanelClass>();    //this will keep records of all of your panels.
    
    MyPanelClass panel_name = new MyClassPanel();
    panel_name.Name = "email_in_" + user_credentials[counter_snel][0];;
    panel_name.Visible = false;
    panel_name.YourLabelsText = string.Format("{0,0}\n{1,0}\n{2,0}", user_credentials[counter_snel][1], user_credentials[counter_snel][2],user_credentials[counter_snel][9]);
    
    //Now add the new created panel to the list.
    myPanelList.Add(panel_name);
    

    Now whenever you need to activate a stored Panel, just do this:

    base_panel.Name = myPanelList[yourPanelsIndex].Name;
    base_panel.Visible = myPanelList[yourPanelsIndex].Visible; //You probably don't need this because base_panel will always be visible
    yourLabel.Text = myPanelList[yourPanelsIndex].YourLabelsText;
    

    This code is much less bulky on the machine and is easy to handle too.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported

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.