TabControl question

S

shoa

Hello
I have a TabControl1 in my Window Form. In this TabControl, I have three
tabs: TabPage1, TabPage2, TabPage3. I also have a button. What I want is
when I am in TabPage2 or TabPage2, I can click this button and I can see
TabPage1 ( I does not want to click on the tab). My code below (for the
button ) does not work
TabControl1.TabPages.Item(0).BringToFront()

Could you please tell me how to do that.

Many thanks

S.Hoa
 
S

stax

shoa said:
Hello
I have a TabControl1 in my Window Form. In this TabControl, I have three
tabs: TabPage1, TabPage2, TabPage3. I also have a button. What I want is
when I am in TabPage2 or TabPage2, I can click this button and I can see
TabPage1 ( I does not want to click on the tab). My code below (for the
button ) does not work
TabControl1.TabPages.Item(0).BringToFront()

Could you please tell me how to do that.

Many thanks

S.Hoa

Hi,

I believe the TabControl has a property for this,
maybe it's called ActiveTab or SelectedTab.

Hope this helps.

stax
 
O

Oenone

shoa said:
My code below (for the button ) does not work
TabControl1.TabPages.Item(0).BringToFront()

Try:

\\\
TabControl1.SelectedIndex = 0
///

You could also use the SelectedTab property if you want; this performs the
same function but takes a reference to a TabPage object instead of a tab
index.

Hope that helps,
 
H

Herfried K. Wagner [MVP]

shoa said:
I have a TabControl1 in my Window Form. In this TabControl, I have three
tabs: TabPage1, TabPage2, TabPage3. I also have a button. What I want is
when I am in TabPage2 or TabPage2, I can click this button and I can see
TabPage1 ( I does not want to click on the tab). My code below (for the
button ) does not work
TabControl1.TabPages.Item(0).BringToFront()

\\\
Me.TabControl1.SelectedTab = Me.TabControl1.TabPages(1)
///

- or -

\\\
Me.TabControl1.SelectedIndex = 1
///
 
S

Simon Verona

Personally, I always prefer referencing the tab by name.. I got caught out
when I reordered the order of tabs after my original development.. Whilst I
guess it's less efficient - you always get the tab you thought you wanted!

Regards
Simon
 
H

Herfried K. Wagner [MVP]

Simon Verona said:
Personally, I always prefer referencing the tab by name.. I got caught out
when I reordered the order of tabs after my original development.. Whilst
I guess it's less efficient - you always get the tab you thought you
wanted!

ACK, it may be better to use the fields generated for the tabpages instead
of the 'TabPages' collection:

\\\
Me.TabControl1.SelectedTab = Me.TabPage1
///

When giving the tab pages meaningful names this will lead to more readable
code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top