The Visible property has not been implemented on the Tabcontrol and there is no Insert method. The following methods are a workaround.
This some sample by: Mick Doherty. demonstrated how to manipulate show and hide tabpages in a tabcontrol. See this code, sample in VB net and Csharp
:
Hide TabPages VB net Sample:
Private Sub HideTabPage(ByVal tp As TabPage) If TabControl1.TabPages.Contains(tp) Then TabControl1.TabPages.Remove(tp) End Sub Private Sub ShowTabPage(ByVal tp As TabPage) ShowTabPage(tp, TabControl1.TabPages.Count) End Sub Private Sub ShowTabPage(ByVal tp As TabPage, ByVal index As Integer) If TabControl1.TabPages.Contains(tp) Then Return InsertTabPage(tp, index) End Sub Private Sub InsertTabPage(ByVal [tabpage] As TabPage, ByVal [index] As Integer) If [index] < 0 Or [index] > TabControl1.TabCount Then Throw New ArgumentException("Index out of Range.") End If TabControl1.TabPages.Add([tabpage]) If [index] < TabControl1.TabCount - 1 Then Do While TabControl1.TabPages.IndexOf([tabpage]) <> [index] SwapTabPages([tabpage], (TabControl1.TabPages(TabControl1.TabPages.IndexOf([tabpage]) - 1))) Loop End If TabControl1.SelectedTab = [tabpage] End Sub Private Sub SwapTabPages(ByVal tp1 As TabPage, ByVal tp2 As TabPage) If TabControl1.TabPages.Contains(tp1) = False Or TabControl1.TabPages.Contains(tp2) = False Then Throw New ArgumentException("TabPages must be in the TabCotrols TabPageCollection.") End If Dim Index1 As Integer = TabControl1.TabPages.IndexOf(tp1) Dim Index2 As Integer = TabControl1.TabPages.IndexOf(tp2) TabControl1.TabPages(Index1) = tp2 TabControl1.TabPages(Index2) = tp1 'Uncomment the following section to overcome bugs in the Compact Framework 'TabControl1.SelectedIndex = TabControl1.SelectedIndex 'Dim tp1Text, tp2Text As String 'tp1Text = tp1.Text 'tp2Text = tp2.Text 'tp1.Text=tp2Text 'tp2.Text=tp1Text End Sub
Hide TabPages Csharp Sample:
private void HideTabPage(TabPage tp) { if (tabControl1.TabPages.Contains(tp)) tabControl1.TabPages.Remove(tp); } private void ShowTabPage(TabPage tp) { ShowTabPage(tp, tabControl1.TabPages.Count); } private void ShowTabPage(TabPage tp , int index) { if (tabControl1.TabPages.Contains(tp)) return; InsertTabPage(tp, index); } private void InsertTabPage(TabPage tabpage, int index) { if (index < 0 || index > tabControl1.TabCount) throw new ArgumentException("Index out of Range."); tabControl1.TabPages.Add(tabpage); if (index < tabControl1.TabCount - 1) do { SwapTabPages(tabpage, (tabControl1.TabPages[tabControl1.TabPages.IndexOf(tabpage) - 1])); } while (tabControl1.TabPages.IndexOf(tabpage) != index); tabControl1.SelectedTab = tabpage; } private void SwapTabPages(TabPage tp1, TabPage tp2) { if (tabControl1.TabPages.Contains(tp1) == false || tabControl1.TabPages.Contains(tp2) == false) throw new ArgumentException("TabPages must be in the TabControls TabPageCollection."); int Index1 = tabControl1.TabPages.IndexOf(tp1); int Index2 = tabControl1.TabPages.IndexOf(tp2); tabControl1.TabPages[Index1] = tp2; tabControl1.TabPages[Index2] = tp1; //Uncomment the following section to overcome bugs in the Compact Framework //tabControl1.SelectedIndex = tabControl1.SelectedIndex; //string tp1Text, tp2Text; //tp1Text = tp1.Text; //tp2Text = tp2.Text; //tp1.Text=tp2Text; //tp2.Text=tp1Text; }
1 comments:
Excellent ...
Thank you
Post a Comment