QuestionDrag & Drop?

Posts 1–10 of 10 · Page 1 of 1
Drag & Drop?
Okay i have looked and there are barely any tuts for this that i can find (suprising right?) and also ya i cant get it to work at all and the few tuts there are fail hardcore and none work so do any of you guys have an actual working code for this?
one sec...lemme go see if i can make some code for you...

edit: i did a search on MSDN first and found this - Implementing Drag and Drop in Visual Basic .NETⓘ

Code:
Private MouseIsDown As Boolean = False

Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
    ' Set a flag to show that the mouse is down.
    MouseIsDown = True
End Sub

Private Sub TextBox1_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseMove
    If MouseIsDown Then
        ' Initiate dragging.
        TextBox1.DoDragDrop(TextBox1.Text, DragDropEffects.Copy)
    End If
    MouseIsDown = False
End Sub

Private Sub TextBox2_DragEnter(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles TextBox2.DragEnter
    ' Check the format of the data being dropped.
    If (e.Data.GetDataPresent(DataFormats.Text)) Then
        ' Display the copy cursor.
        e.Effect = DragDropEffects.Copy
    Else
        ' Display the no-drop cursor.
        e.Effect = DragDropEffects.None
    End If
End Sub

Private Sub TextBox2_DragDrop(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles TextBox2.DragDrop
    ' Paste the text.
    TextBox2.Text = e.Data.GetData(DataFormats.Text)
End Sub

better than i could have done it.




Thank me if i helped xD
cant get the dang thing to work lol
Quote Originally Posted by guza44_44 View Post
cant get the dang thing to work lol
what problems are you having with it?

post your problem and ill help you with it tomorrow 'morning....that is if someone else dont help you with it. its almost 12o clock here and i gotta get up at 5 -.- was long day at work to today... lol
when i try to move an image over it just doesnt show the image when i drop at all...just does nothing thats all the info i have plain and simple, im trying to do this for images and a picturebox
Quote Originally Posted by guza44_44 View Post
when i try to move an image over it just doesnt show the image when i drop at all...just does nothing thats all the info i have plain and simple, im trying to do this for images and a picturebox
heres code for draggin and dropping a picture
the previous one was for dragging a text so thats why it didnt work.

Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
    ' Enable dropping.
    PictureBox2.AllowDrop = True
End Sub

Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
    If Not PictureBox1.Image Is Nothing Then
        ' Set a flag to show that the mouse is down.
        m_MouseIsDown = True
    End If
End Sub

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
    If m_MouseIsDown Then
        ' Initiate dragging and allow either copy or move.
        PictureBox1.DoDragDrop(PictureBox1.Image, DragDropEffects.Copy Or _
DragDropEffects.Move)
    End If
    m_MouseIsDown = False
End Sub

Private Sub PictureBox2_DragEnter(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragEnter
    If e.Data.GetDataPresent(DataFormats.Bitmap) Then
        ' Check for the CTRL key. 
        If e.KeyState = 9 Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.Move
        End If
    Else
        e.Effect = DragDropEffects.None
    End If
End Sub

Private Sub PictureBox2_DragDrop(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragDrop
    ' Assign the image to the PictureBox.
    PictureBox2.Image = e.Data.GetData(DataFormats.Bitmap)
    ' If the CTRL key is not pressed, delete the source picture.
    If Not e.KeyState = 8 Then
        PictureBox1.Image = Nothing
    End If
End Sub
ya i know i converted it into picture but now it STILL wont work...idk why...thanks though
Quote Originally Posted by guza44_44 View Post
ya i know i converted it into picture but now it STILL wont work...idk why...thanks though
you do know its got hotkeys right?
erm......no... -.- i shall try again
Quote Originally Posted by guza44_44 View Post
erm......no... -.- i shall try again
read what it says on MSDN, that may help you out.
Posts 1–10 of 10 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Talk with us