tags:

views:

207

answers:

3

In a C# GUI program how do you move a tab control to the front on the click of an object?

I have a picture box on the main tab, when the user clicks on the picture box, I want the second tab to be pulled forward.

Visual Studio 2005

Cheers.

+4  A: 

Are you trying to select a different tab or bring a TabControl in front of a different control?

If the former, write tabControl.SelectedTab = someTabPage in the picture box's Click event.

If the latter, write tabControl.BringToFront().

SLaks
Doh, beat me to it... Good explanation on both methods.
jheddings
My 500th answer!
SLaks
A: 

To select a different tab, set the SelectedTab index from your handler:

// select the second tab in the control
tabControl1.SelectedTab = tabControl1.TabPages[1];
jheddings
+1  A: 

You want to handle the Click event on the control (add a handler to Control.OnClick) containing the picture, and if you have tabControl and myTabPage is the tab page that you want to be selected after the click, you would use TabControl.SelectedPage:

tabControl.SelectedTab = myTabPage;

In particular, since you refer to the "second tab" then you probably want

tabControl.SelectedTab = tabControl.TabPages[1];
Jason
+1 for the detail on the handler.
jheddings
Actually, `OnClick` is a function, not an event. You want the `Click` event.
SLaks
@SLaks: Thanks. Sloppy on my part.
Jason