Picturebox Backcolor Drag and Drop Swap
Picturebox Backcolor Drag and Drop Swap
Picturebox Backcolor Drag and Drop Swap
Picturebox Backcolor Drag and Drop Swap
Picturebox Backcolor Drag and Drop Swap
Picturebox Backcolor Drag and Drop Swap Picturebox Backcolor Drag and Drop Swap Picturebox Backcolor Drag and Drop Swap Picturebox Backcolor Drag and Drop Swap Picturebox Backcolor Drag and Drop Swap Picturebox Backcolor Drag and Drop Swap Picturebox Backcolor Drag and Drop Swap Picturebox Backcolor Drag and Drop Swap
Picturebox Backcolor Drag and Drop Swap Picturebox Backcolor Drag and Drop Swap
Picturebox Backcolor Drag and Drop Swap
Go Back  Xtreme Visual Basic Talk > > > Picturebox Backcolor Drag and Drop Swap


Reply
 
Thread Tools Display Modes
  #1  
Old 05-13-2016, 04:11 PM
SCylant SCylant is offline
Newcomer
 
Join Date: May 2008
Posts: 3
Default Picturebox Backcolor Drag and Drop Swap


I want to drag picturebox1.background = blue, to, picturebox2.background = green, resulting in picturebox1.background = green, and, picturebox2 = blue. I can mousedown pb1 and make pb2 blue, but pb1 also remains blue.
Mousedown to capture pb1 and color, mouse over/up pb2 only results in the pb1 mouseup event, and cannot capture pb2 and color. What is if any are my options to capture the mouseup on pb2 to capture its properties?
Reply With Quote
  #2  
Old 05-16-2016, 02:07 AM
passel's Avatar
passelPicturebox Backcolor Drag and Drop Swap passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

What is the purpose of the color swapping?
Does it have to be a picturebox?
If I just needed colored rectangles that I could drag on and swap the colors I would just draw them using FillRectangle calls, and use the intersect method of the rectangle to detect in which rectangle a mouse down and a mouse up occurred.

If you feel you want to use controls, does it have to be a picturebox?
You can change the background color of a label (set autosize to false so you can make the control the same size as your picturebox and use them in place of the picturebox) or the background color of a panel.

An advantage to using a label or panel control is that they support Drag and Drop.
A picturebox doesn't support Drag and Drop.

As an example, I put six panels on a form, setting three of the backgrounds red, and three of them blue.
I enabled the AutoDrop property on all six controls.
I tried passing the panel as the drag object but couldn't cast it correctly on the drop side, so gave up trying as I don't have the time to figure out if it could be done.
I just copy the reference to a form scope level variable instead.
For the example I just use the same event handlers for all six panels.
Code:
Public Class Form1
  Dim p1 As Panel
  Dim p2 As Panel
  Private Sub Panel_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles Panel6.MouseDown,
                  Panel5.MouseDown, Panel4.MouseDown, Panel3.MouseDown, Panel2.MouseDown, Panel1.MouseDown
    p1 = DirectCast(sender, Panel)
    p1.DoDragDrop("dummy", DragDropEffects.Copy)
  End Sub

  Private Sub Panel_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles Panel6.DragEnter,
                  Panel5.DragEnter, Panel4.DragEnter, Panel3.DragEnter, Panel2.DragEnter, Panel1.DragEnter
    p2 = DirectCast(sender, Panel)
    e.Effect = DragDropEffects.Copy
    Debug.Print("Swaping {0}.backcolor with {1}.backcolor", p1.Name, p2.Name)
  End Sub

  Private Sub Panel_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles Panel6.DragDrop,
                  Panel5.DragDrop, Panel4.DragDrop, Panel3.DragDrop, Panel2.DragDrop, Panel1.DragDrop
    Dim c As Color = p1.BackColor
    p1.BackColor = p2.BackColor
    p2.BackColor = c
  End Sub
End Class
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply

Tags
blue, drop, swap, drag, backcolor, picturebox


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Picturebox Backcolor Drag and Drop Swap
Picturebox Backcolor Drag and Drop Swap
Picturebox Backcolor Drag and Drop Swap Picturebox Backcolor Drag and Drop Swap
Picturebox Backcolor Drag and Drop Swap
Picturebox Backcolor Drag and Drop Swap
Picturebox Backcolor Drag and Drop Swap Picturebox Backcolor Drag and Drop Swap Picturebox Backcolor Drag and Drop Swap Picturebox Backcolor Drag and Drop Swap Picturebox Backcolor Drag and Drop Swap Picturebox Backcolor Drag and Drop Swap Picturebox Backcolor Drag and Drop Swap
Picturebox Backcolor Drag and Drop Swap
Picturebox Backcolor Drag and Drop Swap
 
Picturebox Backcolor Drag and Drop Swap
Picturebox Backcolor Drag and Drop Swap
 
-->