Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Drop 'n drag (and stay)
Message
De
15/01/2005 10:20:32
 
 
À
14/01/2005 18:30:53
Victor Verheij
International Film Festival Rotterdam
Rotterdam, Pays-Bas
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB.NET 1.1
OS:
Windows XP SP2
Divers
Thread ID:
00977399
Message ID:
00977455
Vues:
34
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform