Navigate tabs in a Winforms Tab Control

Posted on 2011-04-25
Medium Priority
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
  • 2
  • 2
LVL 86

Accepted Solution

Mike Tomlinson earned 750 total points
ID: 35464423
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

ID: 35464508
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 86

Expert Comment

by:Mike Tomlinson
ID: 35464517
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

ID: 35464600
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

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

619 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