473,564 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2830
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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call
TabControl1.Tab Pages.Clear()
TabControl1.Vis ible = False ' hide by default
End Sub

Private Sub CheckBox1_Check edChanged(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles CheckBox1.Check edChanged

ShowHideTab(Tab Names.Changes)

' light the button up when pressed...
If CheckBox1.Check State = CheckState.Chec ked Then
CheckBox1.ForeC olor = Color.White
CheckBox1.BackC olor = Color.Green
CheckBox1.Font = New Font(Me.Font.Na me, Me.Font.Size,
FontStyle.Bold)
Else
CheckBox1.ForeC olor = SystemColors.Co ntrolText
CheckBox1.BackC olor = SystemColors.Co ntrol
CheckBox1.Font = Nothing
End If

End Sub

Private Sub CheckBox2_Check edChanged(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles CheckBox2.Check edChanged

ShowHideTab(Tab Names.Transfer)

If CheckBox2.Check State = CheckState.Chec ked Then
CheckBox2.ForeC olor = Color.White
CheckBox2.BackC olor = Color.Green
CheckBox2.Font = New Font(Me.Font.Na me, Me.Font.Size,
FontStyle.Bold)

Else
CheckBox2.ForeC olor = SystemColors.Co ntrolText
CheckBox2.BackC olor = SystemColors.Co ntrol
CheckBox2.Font = Nothing

End If
End Sub

Private Sub CheckBox3_Check edChanged(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles CheckBox3.Check edChanged
ShowHideTab(Tab Names.Leave)

If CheckBox3.Check State = CheckState.Chec ked Then
CheckBox3.ForeC olor = Color.White
CheckBox3.BackC olor = Color.Green
CheckBox3.Font = New Font(Me.Font.Na me, Me.Font.Size,
FontStyle.Bold)

Else
CheckBox3.ForeC olor = SystemColors.Co ntrolText
CheckBox3.BackC olor = SystemColors.Co ntrol
CheckBox3.Font = Nothing

End If
End Sub

Private Sub CheckBox4_Check edChanged(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles CheckBox4.Check edChanged

ShowHideTab(Tab Names.Term)

If CheckBox4.Check State = CheckState.Chec ked Then
CheckBox4.ForeC olor = Color.White
CheckBox4.BackC olor = Color.Green
CheckBox4.Font = New Font(Me.Font.Na me, Me.Font.Size,
FontStyle.Bold)

Else
CheckBox4.ForeC olor = SystemColors.Co ntrolText
CheckBox4.BackC olor = SystemColors.Co ntrol
CheckBox4.Font = Nothing

End If

End Sub

Private Sub ShowHideTab(ByV al i As TabNames)

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

TabControl1.Vis ible = True
Select Case i
Case TabNames.Change s

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

Case TabNames.Transf er

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

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

Case TabNames.Term

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

End Select

Me.Cursor = Cursors.Default
Else
_tabs(i) = Nothing
Select Case i
Case TabNames.Change s
TabControl1.Tab Pages.Remove(Ta bPage1)
Case TabNames.Transf er
TabControl1.Tab Pages.Remove(Ta bPage2)
Case TabNames.Leave
TabControl1.Tab Pages.Remove(Ta bPage3)
Case TabNames.Term
TabControl1.Tab Pages.Remove(Ta bPage4)
End Select

If TabControl1.Tab Count = 0 Then
TabControl1.Vis ible = False
End If
End If

End Sub

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

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

TabControl1.Sel ectedTab = currentTab
End Sub

"Richard" <ri*****@home.c om> wrote in message
news:uh******** ******@TK2MSFTN GP10.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@DON T_SPAM_ME_hotma il.com> wrote in message
news:eQ******** *****@TK2MSFTNG P10.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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call
TabControl1.Tab Pages.Clear()
TabControl1.Vis ible = False ' hide by default
End Sub

Private Sub CheckBox1_Check edChanged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles CheckBox1.Check edChanged

ShowHideTab(Tab Names.Changes)

' light the button up when pressed...
If CheckBox1.Check State = CheckState.Chec ked Then
CheckBox1.ForeC olor = Color.White
CheckBox1.BackC olor = Color.Green
CheckBox1.Font = New Font(Me.Font.Na me, Me.Font.Size,
FontStyle.Bold)
Else
CheckBox1.ForeC olor = SystemColors.Co ntrolText
CheckBox1.BackC olor = SystemColors.Co ntrol
CheckBox1.Font = Nothing
End If

End Sub

Private Sub CheckBox2_Check edChanged(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles CheckBox2.Check edChanged

ShowHideTab(Tab Names.Transfer)

If CheckBox2.Check State = CheckState.Chec ked Then
CheckBox2.ForeC olor = Color.White
CheckBox2.BackC olor = Color.Green
CheckBox2.Font = New Font(Me.Font.Na me, Me.Font.Size,
FontStyle.Bold)

Else
CheckBox2.ForeC olor = SystemColors.Co ntrolText
CheckBox2.BackC olor = SystemColors.Co ntrol
CheckBox2.Font = Nothing

End If
End Sub

Private Sub CheckBox3_Check edChanged(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles CheckBox3.Check edChanged
ShowHideTab(Tab Names.Leave)

If CheckBox3.Check State = CheckState.Chec ked Then
CheckBox3.ForeC olor = Color.White
CheckBox3.BackC olor = Color.Green
CheckBox3.Font = New Font(Me.Font.Na me, Me.Font.Size,
FontStyle.Bold)

Else
CheckBox3.ForeC olor = SystemColors.Co ntrolText
CheckBox3.BackC olor = SystemColors.Co ntrol
CheckBox3.Font = Nothing

End If
End Sub

Private Sub CheckBox4_Check edChanged(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles CheckBox4.Check edChanged

ShowHideTab(Tab Names.Term)

If CheckBox4.Check State = CheckState.Chec ked Then
CheckBox4.ForeC olor = Color.White
CheckBox4.BackC olor = Color.Green
CheckBox4.Font = New Font(Me.Font.Na me, Me.Font.Size,
FontStyle.Bold)

Else
CheckBox4.ForeC olor = SystemColors.Co ntrolText
CheckBox4.BackC olor = SystemColors.Co ntrol
CheckBox4.Font = Nothing

End If

End Sub

Private Sub ShowHideTab(ByV al i As TabNames)

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

TabControl1.Vis ible = True
Select Case i
Case TabNames.Change s

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

Case TabNames.Transf er

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

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

Case TabNames.Term

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

End Select

Me.Cursor = Cursors.Default
Else
_tabs(i) = Nothing
Select Case i
Case TabNames.Change s
TabControl1.Tab Pages.Remove(Ta bPage1)
Case TabNames.Transf er
TabControl1.Tab Pages.Remove(Ta bPage2)
Case TabNames.Leave
TabControl1.Tab Pages.Remove(Ta bPage3)
Case TabNames.Term
TabControl1.Tab Pages.Remove(Ta bPage4)
End Select

If TabControl1.Tab Count = 0 Then
TabControl1.Vis ible = False
End If
End If

End Sub

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

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

TabControl1.Sel ectedTab = currentTab
End Sub

"Richard" <ri*****@home.c om> wrote in message
news:uh******** ******@TK2MSFTN GP10.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
2007
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 tabPage includes the controls. Any examples, documentation or comments would be helpful. tia meh
0
1250
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 DataGridView control. On FormLoad, I bind the grids to DataTables and set the grid columns' HeaderText to the column captions from the DataTables. The...
5
5139
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 different from the one that appears in all XP programs. Is it some reference that I need to add, or what? Second question is specifically about...
8
4136
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 ). This TBC1 contents n TabPages ( TBP1,2,3,..,n) For each TBPn i 've got an specific usercontrol which have controls and code ( data access, ......
5
3328
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 advance Zadkin
2
2836
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 irrelevent to the question). I've noticed, however, that the actual drawing canvas of the tabpage is not flush with the edge of the tabpage. There is...
0
1611
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 OK/Cancel buttons. On the TabControl, there are a few tab pages. Each page has different number of controls. My question is: Should I create...
0
2350
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 an application which has UserControls (GUI pages) with TabControls on it. This TabControls are Usercontrols derived from Windows.Forms.TabControl....
2
2774
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 in a TreeView. So the the application starts by displaying no tabs and adds them in as required. There could be any number of each tab (0 upwards). ...
0
7665
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.