Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add close button on each tab using TabControl

Status
Not open for further replies.

kwestor

MIS
Apr 14, 2003
6
PH
I'm using vb .net's TabControl built-in component (version 2).

How am i going to add a close or any button to each of the tabs in my tab control? I also want to this during runtime so that when i add a tab, the close button is automatically added. i have seen some third-party controls that i can use to that but i just want to use the built-in component from vb .net.

can anyone help me with this? any dot net gurus?
 
This code does what you want. I put the code to add the tabpage and the button on the tabpage in a nother button click event for testing. You can of course put it where you need it.

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

'create a new TabPage
Dim tp As New TabPage

'set TabPage properties
tp.Name = "TabPage" & TabControl1.TabPages.Count
tp.Text = "New Tab" & TabControl1.TabPages.Count + 1

'Create a new button
Dim btn As New Button

'add the new button to the TabPage just created above
btn.Parent = tp

'set button properties (location, etc.)
btn.Left = 100
btn.Top = 100
btn.Width = 88
btn.Height = 24
btn.Text = "Close"
btn.Visible = True

'assign Click event handler to the button's Click event
AddHandler btn.Click, AddressOf btn_Click

'add the new TabPage to the TabControl
TabControl1.TabPages.Add(tp)

End Sub



Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

'Remove the TabPage containg the button from the TabControl
TabControl1.TabPages.Remove(CType(sender.parent, TabPage))

End Sub

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
thanks for the reply jebenson.

i'm sory i forgot to indicate that the button i mean is a close button that is just beside the text of the tabpage.
just like an opera web browser that each page that is open has its own close button so that you can easily close that page if you want without making that page as 'selected page'.

i really want my TabControl to look like an opera browser.
thanks in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top