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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:09:58+00:00 2026-05-26T06:09:58+00:00

I have a Windows Forms app that contains a groupbox with about 30 controls.

  • 0

I have a Windows Forms app that contains a groupbox with about 30 controls. For the sake of example, let’s say that there are 15 labels and 15 textboxes. This groupbox and the controls in it are used to display three different scenarios:

Scenario 1 – requires all of the controls to be visible

Scenario 2 – requires label/textbox #1, 4, 11 and 14 to be visible and the others to be hidden

Scenario 3 – requires label/textbox #3, 9, 11 and 13 to be visible and the others to be hidden

Scenario 1 is obviously straightforward enough. But the other two scenarios are a little more work. Originally, I wrote code to manually show/hide each of the controls like this:

ConfigureUIForScenario2()
{
    label1.visible = true;
    textbox1.visible = true;
    label2.visible = false;
    textbox2.visible = false;
    label3.visible = false;
    textbox3.visible = false;
    label4.visible = true;
    textbox4.visible = true;
    ...
}

That was extremely unwieldy and it just seems like there must be another way. I was looking at panels to organize the controls but since the controls that need to be shown/hidden in scenario 2 and 3 aren’t generally adjacent to one another, the best that that idea yielded was being able to put each label and corresponding textbox into a panel and show/hide the panel. Setting the visibility of 15 panels is, of course, less work than manually setting 30 individual controls, but I’m wondering if there’s a better way still? I am now considering having three panels (one for each scenario) and only adding the necessary controls to each panel. I’m wondering if there’s any sort of best practice with regard to layout problems like this?

  • 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-26T06:09:59+00:00Added an answer on May 26, 2026 at 6:09 am

    You can create a List<Control> or a Control[] for each scenario, then loop through the controls in the lists and set their Visible properties as appropriate.

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

Sidebar

Related Questions

I have a .NET application that contains a checkbox (System.Windows.Forms.Checkbox). This component (WindowsForms10.BUTTON.app.0.378734a1) is
In a C#, Windows forms app, we have a series of user controls that
I have a windows forms app with a textbox control that I want to
I have a Windows Forms app, that has a single ElementHost containing a WPF
I have a Windows Forms app that itself launches different threads to do different
I have a Windows Forms App that loads a dll @ runtime and executes
I have a Windows Forms app that is able to open up a console
I have a windows forms app with a maskedtextbox control that I want to
I have a windows forms app that I am checking all the serial ports
I have a windows forms app running on a machine that is not on

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.