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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:31:35+00:00 2026-06-10T21:31:35+00:00

I just started breaking up my GUI application into UserControls. I have a TabControl

  • 0

I just started breaking up my GUI application into UserControls. I have a TabControl with a bunch of TagePages. Obviously my MainForm.cs file was filled up with tons of events and controls etc and it got very messy quick.

So a previous question gained me the insight of how to create a UserControl. I intend on creating a UserControl for each TabPage and I was wondering how I can interact with Components on the main form or other UserControls.

Here is an example of a TabPage that I have made using a UserControl, which needs to Enable or Disable a button depending which TabPage is currently selected. Is this proper usage or is there a better way?

public partial class TabDetails : UserControl
{
    private RequestForm fRequestForm;
    public TabDetails()
    {
        InitializeComponent();
    }

    public void CustomInitialization(RequestForm pRequestForm)
    {
        fRequestForm = pRequestForm;
        pRequestForm.TabControl_Main.SelectedIndexChanged += SelectedTabIndexChanged;
    }

    private void SelectedTabIndexChanged(object pSender, EventArgs pEvents)
    {
        fRequestForm.Button_SubmitRequest.Enabled = fRequestForm.TabControl_Main.SelectedTab != fRequestForm.Tab_Details;
    }
}

In the MainForm.cs constructor I call:

this.tab_Details1.CustomInitialization(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-06-10T21:31:36+00:00Added an answer on June 10, 2026 at 9:31 pm

    This doesn’t look like a good use of a user control. The user control should not decide how things in the form should behave when something is changed in the user control. A user control should be unaware of its container and should operate in any container.

    The user control should notify the form that something has changed without telling what’s the internal implementation and the form should decide what to do.

    Example:
    A user control named “NameUserControl” consists of TitleComboBox, FirstNameTextBox and LastNameTextBox. The user control wants to notify when one of the values has changed.

    Wrong Way:

    Create events:

    TitleComboBox – SelectedIndexChanged.
    FirstNameTextBox, LastNameTextBox – TextChanged.

    The problems here:

    1. You expose the internal controls behavior. What will happen if you want to change the TitleComboBox to TextBox? You’ll have to change the event name and implementation.
    2. You expose the fact that you use exactly 3 different controls. What will happen if you want to use the same text box for first and last name? You’ll have to delete one event and change the name of the other.

    Good Way:

    Create only a single event: NameChanged and expose 1 property of FullName or three different properties for the values.

    Either way the form subscribe to the event and decide what to do next.

    Another thing to think about: the more you add more functionality to your user control, you either make it less reusable or you make its code more complex. For example, if you add validation inside the user control, you’ll find one day that you need it without validation, so you’ll add a property “bool ValidateData” or it will be so complicated that you’ll need to build another control. One way to solve that is to build very small user controls, but combine them in one or more bigger user controls that fit all your current needs.

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

Sidebar

Related Questions

I have started HTML. I am making tables in it. I just tried breaking
JSLint works fine for just one JavaScript file. Recently, I've started breaking my program
Just started to use Mercurial. Wow, nice application. I moved my database file out
Just started mongo and started having issue with querying already. i have a collection
Just started my first MVC 2.0 .net application. And I set up some default
Just started learning PySide and is having problem with QTimer I have this #!/usr/bin/python
I am learning OpenGL and just started getting into lighting. I enable lighting and
Just started looking into Entity Framework and the new Code-First features. My question is
Just started learning python (3.2) and have a question. I have created a some
Just started using carrierwave with Rails and things have been going smoothly with one

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.