tags:

views:

30

answers:

2

Hi,

I'm making a context menu strip appear during the right clicking of either a selected or unselected tab in the tab strip of a winforms tabcontrol. It's going to have close, and close all but this for now. Anyway, I need to be able to capture which tab the mouse is over when the right click is pressed. Anyone know how?

Another solution that I'd accept is one that selects the unselected tab with a right click before the context menu is shown.

Thanks!

+1  A: 

In your mouse click event you can add this code to find it, if tabs is your tabcontrol

for (int i = 0; i < tabs.TabCount; ++i) {
     if (tabs.GetTabRect(i).Contains(e.Location)) {
         //tabs.Controls[i]; // this is your tab
     }
}
Patrick
this appears to be what I want, i'll upvote/accept when i get it working!
IsaacB
works, thanks buddy!
IsaacB
@IsaacB: np, gl with the rest :)
Patrick
A: 

The sender parameter of the event handler usually gives you the object that you clicked on.

void whatever_OnClick(object sender, EventArgs e) {
  var tab = sender as TabControlClassHere;
}
Zachary Yates
It tells me the tabcontrol that i clicked on, which doesn't help. There's only one tabcontrol! Thanks for the suggestion anyway!
IsaacB