Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Drop 'n drag (and stay)
Message
From
15/01/2005 10:20:32
 
 
To
14/01/2005 18:30:53
Victor Verheij
International Film Festival Rotterdam
Rotterdam, Netherlands
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB.NET 1.1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
00977399
Message ID:
00977455
Views:
33
Victor,

The xy point where the button is dropped is relative to the entire screen ... not just the form and not just the panel. You'll have to do some math to get it right, offsetting by both the form's location and the panel's location. Try this:
        Dim xy As New System.Drawing.Point(e.X, e.Y)
        xy.Offset(-me.Location.X, -me.Location.Y)
        xy.Offset(-pnlDrop.Location.X, -pnlDrop.Location.Y)
~~Bonnie



>Hi, haven't been here for a while....
>
>Buisy learning .net
>
>Wel, probably this is not the right place for my question but, here ik comes.
>
>I'm trying to drop a button on a panel at the location where i release the mouse.
>
>I've got the drag and drop part down, but can't figure out how to let is stay on the location in the panel where i release my mouse.
>
>Below is the code i have.
>
>
>Public Class Form1
>    Inherits System.Windows.Forms.Form
>    Private m_PickedUp As Button
>
>    Private Sub btnDrag_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnDrag.MouseDown
>        m_PickedUp = CType(sender, Button)
>        m_PickedUp.DoDragDrop(sender, DragDropEffects.Copy)
>    End Sub
>
>    Private Sub pnlDrop_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pnlDrop.DragEnter
>        e.Effect = DragDropEffects.Copy
>    End Sub
>
>    Private Sub pnlDrop_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pnlDrop.DragDrop
>        Dim theBtn As Button = CType(m_PickedUp, Button)
>        pnlDrop.Controls.Add(theBtn)
>        'theBtn.Top = e.X
>        'theBtn.Left = e.Y
>        Dim xy As New System.Drawing.Point(e.X, e.Y)
>        theBtn.Location = xy
>        theBtn.Text = e.X.ToString & " : " & e.Y.ToString 'to get an idea of what is happening.
>    End Sub
>End Class
>
>
>Any help is very much appreciated
>thanks, Victor
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform