473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

TabControl Question

Hi,

Simple tabcontrol question:

I have a tab control with a number of tabpages on it. What I want is to
show a particular tabpage when I click a button that is not on the
tabcontrol. Can anyone tell me how I would code this?

Thanks
Richard
Nov 20 '05 #1
2 2812
Here is some code I have that does that.

I have four checkboxs across the top (appearance properties = Button). When
you check/depress the button, it shows corresponding Tabpage. When no
buttons are pressed, TabControl is hidden:

Good luck,
Greg
' class level variables
Private _tabs(3) As TabPage

' the names of my 4 tabs...
Enum TabNames
Changes
Transfer
Leave
Term
End Enum
Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
TabControl1.TabPages.Clear()
TabControl1.Visible = False ' hide by default
End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CheckBox1.CheckedChanged

ShowHideTab(TabNames.Changes)

' light the button up when pressed...
If CheckBox1.CheckState = CheckState.Checked Then
CheckBox1.ForeColor = Color.White
CheckBox1.BackColor = Color.Green
CheckBox1.Font = New Font(Me.Font.Name, Me.Font.Size,
FontStyle.Bold)
Else
CheckBox1.ForeColor = SystemColors.ControlText
CheckBox1.BackColor = SystemColors.Control
CheckBox1.Font = Nothing
End If

End Sub

Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged

ShowHideTab(TabNames.Transfer)

If CheckBox2.CheckState = CheckState.Checked Then
CheckBox2.ForeColor = Color.White
CheckBox2.BackColor = Color.Green
CheckBox2.Font = New Font(Me.Font.Name, Me.Font.Size,
FontStyle.Bold)

Else
CheckBox2.ForeColor = SystemColors.ControlText
CheckBox2.BackColor = SystemColors.Control
CheckBox2.Font = Nothing

End If
End Sub

Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
ShowHideTab(TabNames.Leave)

If CheckBox3.CheckState = CheckState.Checked Then
CheckBox3.ForeColor = Color.White
CheckBox3.BackColor = Color.Green
CheckBox3.Font = New Font(Me.Font.Name, Me.Font.Size,
FontStyle.Bold)

Else
CheckBox3.ForeColor = SystemColors.ControlText
CheckBox3.BackColor = SystemColors.Control
CheckBox3.Font = Nothing

End If
End Sub

Private Sub CheckBox4_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CheckBox4.CheckedChanged

ShowHideTab(TabNames.Term)

If CheckBox4.CheckState = CheckState.Checked Then
CheckBox4.ForeColor = Color.White
CheckBox4.BackColor = Color.Green
CheckBox4.Font = New Font(Me.Font.Name, Me.Font.Size,
FontStyle.Bold)

Else
CheckBox4.ForeColor = SystemColors.ControlText
CheckBox4.BackColor = SystemColors.Control
CheckBox4.Font = Nothing

End If

End Sub

Private Sub ShowHideTab(ByVal i As TabNames)

If _tabs(i) Is Nothing Then
Me.Cursor = Cursors.WaitCursor

TabControl1.Visible = True
Select Case i
Case TabNames.Changes

_tabs(TabNames.Changes) = TabPage1
SortTabPages(TabPage1)

Case TabNames.Transfer

_tabs(TabNames.Transfer) = TabPage2
SortTabPages(TabPage2)
Case TabNames.Leave

_tabs(TabNames.Leave) = TabPage3
SortTabPages(TabPage3)

Case TabNames.Term

_tabs(TabNames.Term) = TabPage4
SortTabPages(TabPage4)

End Select

Me.Cursor = Cursors.Default
Else
_tabs(i) = Nothing
Select Case i
Case TabNames.Changes
TabControl1.TabPages.Remove(TabPage1)
Case TabNames.Transfer
TabControl1.TabPages.Remove(TabPage2)
Case TabNames.Leave
TabControl1.TabPages.Remove(TabPage3)
Case TabNames.Term
TabControl1.TabPages.Remove(TabPage4)
End Select

If TabControl1.TabCount = 0 Then
TabControl1.Visible = False
End If
End If

End Sub

Private Sub SortTabPages(ByVal currentTab As TabPage)
' To reorder the tabs, clear the collection and add them again

TabControl1.TabPages.Clear()
For Each tab As TabPage In _tabs
If Not tab Is Nothing Then
TabControl1.TabPages.Add(tab)
End If
Next

TabControl1.SelectedTab = currentTab
End Sub

"Richard" <ri*****@home.com> wrote in message
news:uh**************@TK2MSFTNGP10.phx.gbl...
Hi,

Simple tabcontrol question:

I have a tab control with a number of tabpages on it. What I want is to
show a particular tabpage when I click a button that is not on the
tabcontrol. Can anyone tell me how I would code this?

Thanks
Richard

Nov 20 '05 #2
Thanks Greg, that was just what I wanted.

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:eQ*************@TK2MSFTNGP10.phx.gbl...
Here is some code I have that does that.

I have four checkboxs across the top (appearance properties = Button). When you check/depress the button, it shows corresponding Tabpage. When no
buttons are pressed, TabControl is hidden:

Good luck,
Greg
' class level variables
Private _tabs(3) As TabPage

' the names of my 4 tabs...
Enum TabNames
Changes
Transfer
Leave
Term
End Enum
Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
TabControl1.TabPages.Clear()
TabControl1.Visible = False ' hide by default
End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

ShowHideTab(TabNames.Changes)

' light the button up when pressed...
If CheckBox1.CheckState = CheckState.Checked Then
CheckBox1.ForeColor = Color.White
CheckBox1.BackColor = Color.Green
CheckBox1.Font = New Font(Me.Font.Name, Me.Font.Size,
FontStyle.Bold)
Else
CheckBox1.ForeColor = SystemColors.ControlText
CheckBox1.BackColor = SystemColors.Control
CheckBox1.Font = Nothing
End If

End Sub

Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged

ShowHideTab(TabNames.Transfer)

If CheckBox2.CheckState = CheckState.Checked Then
CheckBox2.ForeColor = Color.White
CheckBox2.BackColor = Color.Green
CheckBox2.Font = New Font(Me.Font.Name, Me.Font.Size,
FontStyle.Bold)

Else
CheckBox2.ForeColor = SystemColors.ControlText
CheckBox2.BackColor = SystemColors.Control
CheckBox2.Font = Nothing

End If
End Sub

Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
ShowHideTab(TabNames.Leave)

If CheckBox3.CheckState = CheckState.Checked Then
CheckBox3.ForeColor = Color.White
CheckBox3.BackColor = Color.Green
CheckBox3.Font = New Font(Me.Font.Name, Me.Font.Size,
FontStyle.Bold)

Else
CheckBox3.ForeColor = SystemColors.ControlText
CheckBox3.BackColor = SystemColors.Control
CheckBox3.Font = Nothing

End If
End Sub

Private Sub CheckBox4_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CheckBox4.CheckedChanged

ShowHideTab(TabNames.Term)

If CheckBox4.CheckState = CheckState.Checked Then
CheckBox4.ForeColor = Color.White
CheckBox4.BackColor = Color.Green
CheckBox4.Font = New Font(Me.Font.Name, Me.Font.Size,
FontStyle.Bold)

Else
CheckBox4.ForeColor = SystemColors.ControlText
CheckBox4.BackColor = SystemColors.Control
CheckBox4.Font = Nothing

End If

End Sub

Private Sub ShowHideTab(ByVal i As TabNames)

If _tabs(i) Is Nothing Then
Me.Cursor = Cursors.WaitCursor

TabControl1.Visible = True
Select Case i
Case TabNames.Changes

_tabs(TabNames.Changes) = TabPage1
SortTabPages(TabPage1)

Case TabNames.Transfer

_tabs(TabNames.Transfer) = TabPage2
SortTabPages(TabPage2)
Case TabNames.Leave

_tabs(TabNames.Leave) = TabPage3
SortTabPages(TabPage3)

Case TabNames.Term

_tabs(TabNames.Term) = TabPage4
SortTabPages(TabPage4)

End Select

Me.Cursor = Cursors.Default
Else
_tabs(i) = Nothing
Select Case i
Case TabNames.Changes
TabControl1.TabPages.Remove(TabPage1)
Case TabNames.Transfer
TabControl1.TabPages.Remove(TabPage2)
Case TabNames.Leave
TabControl1.TabPages.Remove(TabPage3)
Case TabNames.Term
TabControl1.TabPages.Remove(TabPage4)
End Select

If TabControl1.TabCount = 0 Then
TabControl1.Visible = False
End If
End If

End Sub

Private Sub SortTabPages(ByVal currentTab As TabPage)
' To reorder the tabs, clear the collection and add them again

TabControl1.TabPages.Clear()
For Each tab As TabPage In _tabs
If Not tab Is Nothing Then
TabControl1.TabPages.Add(tab)
End If
Next

TabControl1.SelectedTab = currentTab
End Sub

"Richard" <ri*****@home.com> wrote in message
news:uh**************@TK2MSFTNGP10.phx.gbl...
Hi,

Simple tabcontrol question:

I have a tab control with a number of tabpages on it. What I want is to
show a particular tabpage when I click a button that is not on the
tabcontrol. Can anyone tell me how I would code this?

Thanks
Richard


Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: meh | last post by:
New to C#... I have a tab page with a handful of controls on it (label, combobox, etc.). Is it possible to "boilerplate a tabPage with the controls "like a MDI childForm" so that adding a new...
0
by: David Veeneman | last post by:
I've come across an odd bit of behavior on the VS 2005 TabControl, and I'm wondering if its a bug, or if I'm missing something. I have a TabControl with five tab pages. Each page has a...
5
by: Max | last post by:
This is a two part question. First, how does one go about designing forms that can reflect the XP theme? Take the TabControl for example, even on default the one that you can use in VB.NET looks...
8
by: ChrisK | last post by:
Hi, I'm beginner with VB.net and i have a trouble... At work, they decided to program with tabcontrol...and i'mm in charge of this ! There is my problem. I've a form with one tabcontrol (TBC1...
5
by: Zadkin | last post by:
Does anyone know, if it's possible to set the orientation of the tabpagebuttons to horizontal instead of vertical when the alignment property of my tabcontrol is set to left or right? Thanks in...
2
by: Rex the Strange | last post by:
I suspect the answer to this question is "you can't," but here goes anyway: I have a tabcontrol which contains, of course, various tabpages (added programmatically at runtime, but this is...
0
by: qinger | last post by:
Hello, I am trying to organize the controls on a TabControl. The tabcontrol is sitting on a dialog with OK and Cancel buttons. So I created 2 TableLaoutPanels -- one for TabControl and one for...
0
by: =?Utf-8?B?TWFydGluIw==?= | last post by:
Hello everybody! Please note that I have posted same question in different forums with no success. So If you tried to help me there, please do not consider the repost as rude! I'm working on...
2
by: Gav | last post by:
I am writing an application where I will have a TabControl and 3 styles of Tabs to go in it, each containing different controls. The tabs will be added to the tabcontrol when items are clicked on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.