Results 1 to 4 of 4

Thread: [2008] TabControl....Tabs with Close Buttons?

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2008
    Posts
    45

    [2008] TabControl....Tabs with Close Buttons?

    I've got a bunch of TabPages inside a TabControl; I'd like to have an easy way for the user to close individual tabs; kinda like IE or FireFox does with their tabs.

    Can I do that using the default Windows Control, without too much work?

  2. #2
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: [2008] TabControl....Tabs with Close Buttons?

    Hi,

    You can try something like this:

    vb Code:
    1. Imports System.Drawing
    2. Imports System.Windows.Forms
    3.  
    4. Public Class Form1
    5.     Inherits Form
    6.     Private tabControl1 As TabControl
    7.     Private tabPage1 As TabPage
    8.     Private button1 As Button
    9.  
    10.     Public Sub New()
    11.         Me.tabControl1 = New TabControl()
    12.         Me.tabPage1 = New TabPage()
    13.         Me.button1 = New Button()
    14.  
    15.         Me.tabControl1.TabPages.Add(tabPage1)
    16.         Me.tabControl1.Location = New Point(25, 25)
    17.         Me.tabControl1.Size = New Size(250, 250)
    18.  
    19.         ' Gets the controls collection for tabPage1.
    20.         ' Adds button1 to this collection.
    21.         Me.tabPage1.Controls.Add(button1)
    22.  
    23.         Me.button1.Text = "button1"
    24.         Me.button1.Location = New Point(25, 25)
    25.  
    26.         Me.ClientSize = New Size(300, 300)
    27.         Me.Controls.Add(tabControl1)
    28.     End Sub
    29.  
    30.     Shared Sub Main()
    31.         Application.Run(New Form1())
    32.     End Sub
    33. End Class

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] TabControl....Tabs with Close Buttons?

    Placing a button on the tabs of a TabControl is not the same thing as placing a Button control on each TabPage.

    The tabs are actually part of the TabControl itself, not each TabPage. As such you would have to owner-draw the tabs and draw your own button.

    http://www.vb-helper.com/howto_net_ownerdraw_tab.html
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    Re: [2008] TabControl....Tabs with Close Buttons?

    Great link, I found it very useful myself. Thanks
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width