Drag and Drop mit Pictureboxen

  • VB.NET

Es gibt 11 Antworten in diesem Thema. Der letzte Beitrag () ist von x_Str.

    Drag and Drop mit Pictureboxen

    Hallo,

    ich hab da ein Problem was das Drag and Drop bei Pictureboxen betrifft.

    Ich hab 3 Pictureboxen, 2 davon haben ein Bild.
    Wenn ich die Frucht in die gekennzeichnete Richtung verschieb verschwindet das Buch, was es aber eigentlich nicht sollte.

    Hier noch Screenshot das es vlt verständlicher ist:



    Uploaded with ImageShack.us



    Code:

    VB.NET-Quellcode

    1. Private m_MouseIsDown As Boolean 'MouseDown Event
    2. Private Sub frm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3. 'Drag and Drop aktivieren
    4. PictureBox1.AllowDrop = True
    5. PictureBox2.AllowDrop = True
    6. PictureBox20.AllowDrop = True
    7. End Sub
    8. Private Sub PictureBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop
    9. PictureBox1.Image = e.Data.GetData(DataFormats.Bitmap)
    10. If Not e.KeyState = 8 Then
    11. PictureBox2.Image = Nothing
    12. PictureBox20.Image = Nothing
    13. End If
    14. End Sub
    15. Private Sub PictureBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragEnter
    16. If e.Data.GetDataPresent(DataFormats.Bitmap) Then
    17. If e.KeyState = 9 Then
    18. e.Effect = DragDropEffects.Copy
    19. Else
    20. e.Effect = DragDropEffects.Move
    21. End If
    22. Else
    23. e.Effect = DragDropEffects.None
    24. End If
    25. End Sub
    26. Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As _
    27. System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
    28. If Not PictureBox1.Image Is Nothing Then
    29. m_MouseIsDown = True
    30. End If
    31. End Sub
    32. Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As _
    33. System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
    34. If m_MouseIsDown Then
    35. PictureBox1.DoDragDrop(PictureBox1.Image, DragDropEffects.Copy Or _
    36. DragDropEffects.Move)
    37. End If
    38. m_MouseIsDown = False
    39. End Sub
    40. Private Sub PictureBox2_DragEnter(ByVal sender As Object, ByVal e As _
    41. System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragEnter
    42. If e.Data.GetDataPresent(DataFormats.Bitmap) Then
    43. If e.KeyState = 9 Then
    44. e.Effect = DragDropEffects.Copy
    45. Else
    46. e.Effect = DragDropEffects.Move
    47. End If
    48. Else
    49. e.Effect = DragDropEffects.None
    50. End If
    51. End Sub
    52. Private Sub PictureBox2_DragDrop(ByVal sender As Object, ByVal e As _
    53. System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragDrop
    54. PictureBox2.Image = e.Data.GetData(DataFormats.Bitmap)
    55. If Not e.KeyState = 8 Then
    56. PictureBox1.Image = Nothing
    57. End If
    58. End Sub
    59. Private Sub PictureBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseDown
    60. If Not PictureBox2.Image Is Nothing Then
    61. m_MouseIsDown = True
    62. End If
    63. End Sub
    64. Private Sub PictureBox2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseMove
    65. If m_MouseIsDown Then
    66. PictureBox1.DoDragDrop(PictureBox2.Image, DragDropEffects.Copy Or _
    67. DragDropEffects.Move)
    68. End If
    69. m_MouseIsDown = False
    70. End Sub
    71. Private Sub PictureBox20_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox20.DragDrop
    72. PictureBox20.Image = e.Data.GetData(DataFormats.Bitmap)
    73. If Not e.KeyState = 8 Then
    74. PictureBox1.Image = Nothing
    75. End If
    76. End Sub
    77. Private Sub PictureBox20_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox20.DragEnter
    78. If e.Data.GetDataPresent(DataFormats.Bitmap) Then
    79. If e.KeyState = 9 Then
    80. e.Effect = DragDropEffects.Copy
    81. Else
    82. e.Effect = DragDropEffects.Move
    83. End If
    84. Else
    85. e.Effect = DragDropEffects.None
    86. End If
    87. End Sub
    88. Private Sub PictureBox20_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox20.MouseDown
    89. If Not PictureBox20.Image Is Nothing Then
    90. m_MouseIsDown = True
    91. End If
    92. End Sub
    93. Private Sub PictureBox20_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox20.MouseMove
    94. If m_MouseIsDown Then
    95. PictureBox1.DoDragDrop(PictureBox20.Image, DragDropEffects.Copy Or _
    96. DragDropEffects.Move)
    97. End If
    98. m_MouseIsDown = False
    99. End Sub




    Mfg
    x_str

    Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „x_Str“ ()

    Überall steht PictureBox1.Image = Nothing drin.

    VB.NET-Quellcode

    1. Private Sub PictureBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop
    2. PictureBox1.Image = New Bitmap(CType(e.Data.GetData(DataFormats.Bitmap), Image))
    3. If Not e.KeyState = 8 Then
    4. PictureBox2.Image = Nothing
    5. PictureBox20.Image = Nothing
    6. End If
    7. End Sub
    8. Private Sub PictureBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragDrop
    9. PictureBox2.Image = New Bitmap(CType(e.Data.GetData(DataFormats.Bitmap), Image))
    10. If Not e.KeyState = 8 Then
    11. PictureBox1.Image = Nothing
    12. End If
    13. End Sub
    14. Private Sub PictureBox20_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox20.DragDrop
    15. PictureBox20.Image = New Bitmap(CType(e.Data.GetData(DataFormats.Bitmap), Image))
    16. If Not e.KeyState = 8 Then
    17. PictureBox1.Image = Nothing
    18. End If
    19. End Sub
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Hast Du meinen letzten Post überhaupt gelesen?
    Was soll denn passieren, wenn Du ein Bild gezogen hast?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Dann musst Du es löschen. :D :D :D
    Merke Dir, welches Bild Du ziehst, und wenn es losgelassen wird, lösch es.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Wenn ich bei dieser Stelle "PictureBox20.Image = Nothing" raus mach verschwindet das Buch nicht mehr.

    VB.NET-Quellcode

    1. Private Sub PictureBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop
    2. PictureBox1.Image = e.Data.GetData(DataFormats.Bitmap)
    3. If Not e.KeyState = 8 Then
    4. 'PictureBox20.Image = Nothing
    5. PictureBox2.Image = Nothing
    6. End If
    7. End Sub



    Dafür aber bleibt dann das buch immer an seiner stelle und ich kanns nicht verschieben
    Dateien
    • DragDrop.rar

      (193,62 kB, 230 mal heruntergeladen, zuletzt: )

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „x_Str“ ()