INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Picturebox MouseDown MouseUp Background Color swap Drag and Drop

Picturebox MouseDown MouseUp Background Color swap Drag and Drop

Picturebox MouseDown MouseUp Background Color swap Drag and Drop

(OP)
I want to mousedown picturebox1(PB1), mouseup picturebox2(PB2) to swap the background colors, Drag and Drop(DND).
Mousedown PB1 returns PB1-blue, mouseup PB2 returns PB1-blue. Form_Mouseup event, groubox_mouseup(PB1,PB2 container) event have no affect.
With that I am having an issue with capturing the Picturebox and color on the mouseup event.

RE: Picturebox MouseDown MouseUp Background Color swap Drag and Drop

(OP)
I apologize I failed to mention PB1 is Blue and PB2 is Green when I initialize the DND action.

CODE -->

'First attempt mouse events' This only turns PB2 to Blue but PB1 is still Blue also but i want it to be Green.
    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown

      Debug.Print("PB1_MouseDown")
      pbControlDn = 1
      Debug.Print("1")
      pbControlDnColor = PictureBox1.BackColor
      Debug.Print(pbControlDnColor.ToString)

    End Sub

    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove

      Debug.Print("PB1_MouseMove")
      If pbControlDn > 0 Then
        pbControlUp = 1
        Debug.Print("1")
        pbControlUpColor = PictureBox1.BackColor
        Debug.Print(pbControlUpColor.ToString)
      End If

    End Sub

    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp

      Debug.Print("PB1_MouseUp")
      Select Case pbControlUp
        Case 1
          Debug.Print(pbControlUpColor.ToString)
          Debug.Print(pbControlDnColor.ToString)
          PictureBox1.BackColor = pbControlUpColor
          PictureBox2.BackColor = pbControlDnColor
          PictureBox1.Refresh()
          PictureBox2.Refresh()
        Case 2
        Case Else
      End Select
      pbControlDn = 0
      pbControlUp = 0

    End Sub

    Private Sub PictureBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseDown

      Debug.Print("PB2_MouseDown")
      pbControlDn = 2
      Debug.Print("2")
      pbControlDnColor = PictureBox2.BackColor
      Debug.Print(pbControlDnColor.ToString)

    End Sub

    Private Sub PictureBox2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseMove

      Debug.Print("PB2_MouseMove")
      If pbControlDn > 0 Then
        pbControlUp = 2
        Debug.Print("2")
        pbControlUpColor = PictureBox2.BackColor
        Debug.Print(pbControlUpColor.ToString)
      End If

    End Sub

    Private Sub PictureBox2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseUp

      Debug.Print("PB2_MouseUp")
      Select Case pbControlUp
        Case 1
        Case 2
          Debug.Print(pbControlUpColor.ToString)
          Debug.Print(pbControlDnColor.ToString)
          PictureBox2.BackColor = pbControlUpColor
          PictureBox1.BackColor = pbControlDnColor
          PictureBox1.Refresh()
          PictureBox2.Refresh()
        Case Else
      End Select
      pbControlDn = 0
      pbControlUp = 0

    End Sub
	
'Second attempt dodragdrop' does nothing
    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown

      Dim PB1 As PictureBox = CType(sender, PictureBox)

      PB1.DoDragDrop(PB1.BackColor, DragDropEffects.Copy)

    End Sub

    Private Sub PictureBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragEnter

      If e.Data.GetDataPresent(DataFormats.Bitmap) Then

        e.Effect = DragDropEffects.Copy

      Else

        e.Effect = DragDropEffects.None

      End If

    End Sub

    Private Sub PictureBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop

      Dim picbox As PictureBox = CType(sender, PictureBox)

      Dim g As Color = picbox.BackColor
      PictureBox1.BackColor = g
      'g.DrawImage(CType(e.Data.GetData(DataFormats.Bitmap), Image), New Point(0, 0))

    End Sub

    Private Sub PictureBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseDown

      Dim PB1 As PictureBox = CType(sender, PictureBox)

      PB1.DoDragDrop(PB1.BackColor, DragDropEffects.Copy)

    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

        e.Effect = DragDropEffects.Copy

      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

      Dim picbox As PictureBox = CType(sender, PictureBox)

      Dim g As Color = picbox.BackColor
      PictureBox2.BackColor = g
      'g.DrawImage(CType(e.Data.GetData(DataFormats.Bitmap), Image), New Point(0, 0))

    End Sub 

RE: Picturebox MouseDown MouseUp Background Color swap Drag and Drop

MSDN gives a very clear example of working with a PictureBox @ https://msdn.microsoft.com/en-us/library/aa289508%...

Since you can set a custom object for dragging and dropping you just need a Color object and it should work as described in the above article.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close