Navigate tabs in a Winforms Tab Control

Posted on 2011-04-25
Last Modified: 2012-05-11
Hello Experts:

I have a winforms tab contol on my main form.  It has, say, 5 tab pages. (tabPage1, tabPage2 etc)

On myTabControl..TabPages[tabPage1] I have added a custom UserControl (userControl1) with a Button (button1) on it.

When I click button1 I want to clear the controls on tabPage3, Add() a new UserControl to that TabPage, then select tabPage3.

How do I wire up the button1_Click event handler to talk to the TabControl and select the appropriate tab?

Should be easy enough, I'm just missing something here..


Question by:cmh_rwhelan
    LVL 85

    Accepted Solution

    Make userControl1 raise a custom event that the FORM subscribes to.  When the event is received, the form will clear tabPage3, add the dynamic UserControl, and select the tab.

    Author Comment

    OK - that's what I am working on at the moment - I just wanted to see if there was any sneaky way of referencing the parent control and passing the event that way -

    I'll get back asap with how it works out.

    LVL 85

    Expert Comment

    by:Mike Tomlinson
    You could also pass in a reference to tabPage3 into your UserControl if you really wanted to...I prefer the event method though.

    Author Closing Comment

    Custom event is the best way to go rather than passing parameters back and forth between parent and child controls - just more to declare and wire up.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 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

    24 Experts available now in Live!

    Get 1:1 Help Now