Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi

I'm having a bit of trouble with removing a tab from a tabcontrol.

 

The user can dynamically add tab, so obviously a way to close them is needed.

First I tried to somehow a button to the tablabel but that has proven to be a little difficult.

Now I just want to close a tab when the user makes a doubleclick on the tablabel.

 

But the doubleclick event doesn't tell me which tab was clicked,

it doesn't even tell me the mouse position.

The clicked event passes the mouse position but I still don't know which tab was clicked.

 

Any idea how I can realize this?

  • Leaders
Posted (edited)

I found a mediocre solution on CodeProject. As far as I can see, the biggest problem is that there is no way to obtain the bounding rectangle for each tab unless you enable owner drawing, which means you lose visual styles.

 

[Edit]Looking around Google, there seem to be plenty of free custom-made tab controls that support close buttons, but you still lose the native OS appearance.[/edit]

Edited by snarfblam
[sIGPIC]e[/sIGPIC]
Posted
Hi

I'm having a bit of trouble with removing a tab from a tabcontrol.

 

The user can dynamically add tab, so obviously a way to close them is needed.

First I tried to somehow a button to the tablabel but that has proven to be a little difficult.

Now I just want to close a tab when the user makes a doubleclick on the tablabel.

 

But the doubleclick event doesn't tell me which tab was clicked,

it doesn't even tell me the mouse position.

The clicked event passes the mouse position but I still don't know which tab was clicked.

 

Any idea how I can realize this?

 

You can add event handlers to your tabpages / tabcontrol dynamically as well

First I tried adding event handlers to the tabpages but this will only trigger when you actually click the page instead of the label. So here is another workaround:

I made a form with a tabcontrol called tabcontrol1

As you click the tab the selectedTab changes as well. This way you know what tab is clicked, since it gets focus before it gets removed.

 

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

       ' Add any initialization after the InitializeComponent() call.
       'For Each p As TabPage In TabControl1.TabPages
       '    AddHandler p.MouseDoubleClick, AddressOf TabPage_Close
       'Next

       AddHandler TabControl1.MouseDoubleClick, AddressOf TabPage_Close

   End Sub

   Private Sub TabPage_Close(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
       TabControl1.TabPages.Remove(CType(sender, TabControl).SelectedTab)
   End Sub

 

~ DP

My Development System

Intel Core i7 920 @2.66Ghz

6 GB DDR3 SDRAM

Windows 7 Ultimate x64 & Windows Vista Home Premium x64 dual boot

GeForce GTX295 1.8 GB

3.5 TB HD

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...