Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Picturebox MouseDown MouseUp Background Color swap Drag and Drop

Status
Not open for further replies.

lrfcbabe

Programmer
Jul 19, 2001
108
US
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.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top