c# - How to determine which tab was right clicked on? -


i have seen question asked multiple times, same answer. reason not work correctly in program.

this basic answer gives question...

for (int = 0; < tabs.tabcount; ++i) {     if (tabs.gettabrect(i).contains(e.location)) {      //tabs.controls[i]; // tab     } } 

this same code using when right click on second tab, closes first tab.

when debug problem, get...

e.location: x=57, y=7 rect(0):    x=2, y=2, width=56, height=18 rect(1):    x=58, y=2, width=99, height=18 

enter image description here

as can see location (2 + 56 = 58) in first tab when click on second one.

what doing wrong? code repeated many times find hard believe doesn't work. looks e.location starting different location tab starts.

update: routine running when right click on tab bring context menu.

private void cmpclose_mouseup(object sender, mouseeventargs e) {     openpdf currentopenpdf;      // iterate through tab pages     (int = 0; < tcdocuments.tabcount; i++)     {         // rectangle area , check if contains mouse cursor         if (tcdocuments.gettabrect(i).contains(e.location))         {             // tab         }     } } 

your e.location value contextmenu has no relationship rectangle area of tabpage header.

try storing value in tabcontrol's mouseup value:

point tabmouse = point.empty;  void tcdocuments_mouseup(object sender, mouseeventargs e) {   tabmouse = e.location; } 

now can use proper click event of menu item:

void printpdftoolstripmenuitem_click(object sender, eventargs e) {   (int = 0; < tcdocuments.tabcount; ++i) {     if (tcdocuments.gettabrect(i).contains(tabmouse)) {       // stuff     }   } } 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -