dragdrop and tabcontrol

G

Guest

I am wishing to drag something from the desktop to a tab of a tab control in
vb.net.
The dragdrop event fires when release the mouse above the tab however i am
having a hard time trying to figure out which tab it was dropped on.

Currently i am using the following code but it is not working..Any help
would be appreciated...

Private Sub tc_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles tc.DragDrop
Dim pt As New Point(e.X, e.Y)
pt = PointToClient(pt)
Dim hover_tab As TabPage = GetTabPageByTab(e.X, e.Y)
If Not hover_tab Is Nothing Then
Debug.Write("got it")
End If
End Sub


Private Function GetTabPageByTab(ByVal x As Integer, ByVal y As Integer)
As TabPage
'Private Function GetTabPageByTab(ByVal pt As Point) As TabPage
Dim tp As TabPage = Nothing
Dim i As Integer = 0
For i = 0 To tc.TabPages.Count - 1
Dim tabRec As System.Drawing.Rectangle = tc.GetTabRect(i)
Debug.WriteLine(DateTime.Now.ToString & " " & i.ToString &
tabRec.X & " " & tabRec.Y & " Point X " & x & " " & y & "____")

If tc.GetTabRect(i).Contains(x, y) Then
tp = tc.TabPages(i)
tc.SelectedIndex = i
Debug.WriteLine(DateTime.Now.ToString & " " & i.ToString)
Exit For
End If
Next
Return tp
End Function
 
M

Mick Doherty

\\\
Private Sub tc_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) _
Handles tc.DragDrop
Dim pt As Point = tc.PointToClient(New Point(e.X, e.Y))
Dim hover_tab As TabPage = GetTabPageByTab(pt)
If Not hover_tab Is Nothing Then
Debug.Write(hover_tab.ToString)
End If
End Sub

Private Function GetTabPageByTab(ByVal pt As Point) As TabPage
For index As Integer = 0 To tc.TabCount - 1
If tc.GetTabRect(index).Contains(pt.X, pt.Y) Then
Return tc.TabPages(index)
End If
Next
Return Nothing
End Function

Private Sub tc_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs) _
Handles tc.DragEnter
e.Effect = DragDropEffects.All
End Sub


///
 
G

Guest

Thank you very much Mike. (I owe you one)

It appears my biggest fault was the issue that pointtoclient is a method of
the tabcontrol. Thanks again.
 

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