TabControl: How to know which tab the mouse is over

A

Anon

I am trying to do a drag and drop operation onto a TabControl...

Here's the scenario:
A TabControl has 5 tabs.
Each tab has a DataGridView

Drag and drop should be able to drag a row from one DataGridView (in one
tab) into another DataGridView (in another tab).
Being that only one DataGridView can be displayed, what I'll do is drag the
row over to the TOP of the TabControl where all of the 5 Tab Headers exist.
From there, if they "drop" the row, I would like to simply take the row out
of the Dragged DataGridView and place it into the DatGridView that's
contained within the tab that they chose to "drop" the row to.

I have a proof of concept partly working. I can do the drag and drop,
however I'm having a problem getting the "tab" index of the tab that they
wish to drop it in...

Is there a way that I can tell which "tab" header (in a TabControl) the
mouse is over when the drop operation is performed? In the DragDrop()
method, I have access to the X,Y coordinate. I cannot find a method or
property which will allow me to figure out which "tab header" the mouse was
over.

I *could* try and generate a mouse click (by calling SendMessage()) and then
overriding the tabChanged() method and having that method determine if a
"drag" operation was in-progress by looking at a boolean (that DragDrop()
would set). If the drag was in-progress, then the tabChanged() method can
conclude it got in the method due to a "drop".

Before I go off and figure out how to get SendMessage() to compile (I saw an
example of using the DllImport annotation (so I could call SendMessage() to
Generate a mouse click event) but could not get the example to compile), I'd
like to know if there is a way to determine which "tab header" corresponds
to an X,Y coordinate.

There is just one tab control in the application.

thanks again for any help....
 
M

Mick Doherty

Loop through the tabpages calling GetTabRect(index) and check if the
returned rectangle Contains(X,Y)
 
A

Anon

Awesome...

Thanks for the reply Mick. This works great and is exactly what I was
looking for.


"Mick Doherty"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top