Move the focus from one tabPage to another How?
Hi guys
I am getting a bit in a muddle with the tabControl
I have a tab control with 5 pages
How can I do this
I am on Tabpage 1
I press a button I want to move on tabpage2
Also
When hiding the tabPage by removing it and then readding it later i want to readd it to the same position (index)
How can I do this?
Thanks
Sorry never played much with the tab Control
vbjunkie
[398 byte] By [
vbjunkie] at [2007-12-16]
Hi,In regards to the second half of your question (removing a tab and then adding it again later to the same index) you can use the following:
| | tabControl1.TabPages.Insert(index, tabPage); |
Where "tabControl1" is the name of the TabControl you want to add the TabPage to, "index" is the index you want to insert the tab into, and "tabPage" is the TabPage that you want to add. Also, in regards to the first half of your question (switching between tabs with a button) a slightly cleaner way of doing this would be the following:
| | if (tabControl1.SelectedIndex < (tabControl1.TabPages.Count - 1)) { tabControl1.SelectedIndex++; } else { tabControl1.SelectedIndex = 0; } |
Since this would allow you to not have to write an if / else clause for each tab, and would allow you to add or remove tabs at runtime like you plan.
Hope this helps.
Scott Morrison
WinForms PM
Microsoft Corp.