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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:13:25+00:00 2026-06-05T16:13:25+00:00

I am new to C#.Net. I have a form with some panels in it.

  • 0

I am new to C#.Net.
I have a form with some panels in it. One of the panels is MainPanel. After start up, the MainPanel is empty. Based on user selection, I want to load some controls in it. Something similar to CardLayout in Java! Each panel have a lot of Controls and I don’t want to add them programatically. In fact the question is “Is there a way to have some panels designed in designer and show/hide them based on user selection, all in one form?”

enter image description here

Thank you.

  • 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-05T16:13:27+00:00Added an answer on June 5, 2026 at 4:13 pm

    Yes, create new objects called UserControls in their own classes. You can add and remove them programmatically, but create them in the designer.

    To keep from getting flicker when changing the controls, do something like the following:

    Control ctlOld = frmMain.Controls[0]; // this will allow you to remove whatever control is in there, allowing you to keep your code generic.
    ctlNextControl ctl = new ctlNextControl(); // this is the control you've created in another class
    frmMain.Controls.Add(ctlNextControl);
    frmMain.Controls.Remove(ctlOld);
    

    Create your User Controls, and name them whatever you wish, I’ll make some names up now for examples:

    ctlGear
    ctlMap
    ctlGraph
    ctlCar
    ctlPerson
    

    Add those 5 files as UserControls to your project. Design them however you want.

    Create an enum for the different buttons for ease of use:

    public enum ControlType {
        Gear,
        Map,
        Graph,
        Car,
        Person
    }
    

    Once you have them created, in the button click events for each of those buttons, add a call to this new method:

    private void SwitchControls(ControlType pType) {
        // Keep a reference to whichever control is currently in MainPanel.
        Control ctlOld = MainPanel.Controls[0];
        // Create a new Control object
        Control ctlNew = null;
        // Make a switch statement to find the correct type of Control to create.
        switch (pType) {
            case (ControlType.Gear):
               ctlNew = new ctlGear();
               break;
            case (ControlType.Map):
               ctlNew = new ctlMap();
               break;
            case (ControlType.Graph):
               ctlNew = new ctlGraph();
               break;
            case (ControlType.Car):
                ctlNew = new ctlCar();
                break;
            case (ControlType.Person):
                ctlNew = new ctlPerson();
                break;
            // don't worry about a default, unless you have one you would want to be the default.
        }
    
        // Don't try to add a null Control.
        if (ctlNew == null) return();
    
        MainPanel.Controls.Add(ctlNew);
    
        MainPanel.Controls.Remove(ctlOld);
    }
    

    Then in your button click events, you could have something like this:

    private void btnGear.Click(object sender, EventArgs e) {
        SwitchControls(ControlType.Gear);
    }
    

    The same thing would be in the other click events, just change out the ControlType in the parameters.

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

Sidebar

Related Questions

I am new to ASP.NET MVC, particularly ajax operations. I have a form with
Question ONE: I'm still pretty new to .net, but have used Visual Studio for
ASP.Net MVC 3 using C# I currently have a form with some dropdown lists
i have been working on a new .net MVC site and have integrated some
I have a form in my asp.net mvc(C#) application which handles some dynamic controls.
I'm developing a web app with asp.net mvc 3 and I have some form
I am new ASP.NET and I have never used a GridView or DataGrid, but
I have a new asp.net mvc project and i am trying to figure out
I am new to .Net. I have two objects, Customer and Country in my
I'm developing a new client-server app (.Net) and have up until now been using

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.