473,326 Members | 2,136 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,326 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 2807
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.