Detect color of pixel on picture box

I am allowing user to drag/drop an image box around on a picturebox, but I don't want the user to be able to drop the image box onto the picturebox where the pixels are not blue.  Also, I have another image box where I want it to not be able to be dropped on any blue pixels.  Any ideas?
LVL 1
VingamelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)

   If Picture1.PSet(X, Y) = vbBlue Then
   End If
   
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VingamelAuthor Commented:
I am trying to test this out, but boy do I feel dumb...I can't remember how to do this, but when I drag the imagebox onto the picture box, the imagebox hides behind the picturebox.

Private Sub Image1_DragDrop(Source As Control, X As Single, Y As Single)
Source.Move X, Y
Source.ZOrder (0)
End Sub



Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
    Source.Move X, Y
    Source.ZOrder (0)
End Sub
0
Bob LearnedCommented:
You don't have to feel dumb, but what you are referring to is a functionality difference between image controls and picture boxes.

The image control is a lightweight control, like a label, and it does not have a Window handle (hWnd).  

Because of this, the control is actually part of the form.  Its ZOrder cannot be changed like other controls that have Window handles.

You can check this out by placing an Image control on top a picture box in the design mode.  You will notice that the image control will not go in front, but will go directly behind the picture box.

The real question is what are you trying to do?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Bob LearnedCommented:
You could make the image control part of the picture box, so that it doesn't move outside of the dimensions of the picture box.
0
VingamelAuthor Commented:
I am using bitblt to paint multiple pictures on picBack, and then using an imagebox to dragdrop onto the picture.  The picBack is a map of a continent, and the imagebox is for units such as ships and soldiers.  I would just bitblt and animate the units directly onto the picBack, but want the user to be able to click on the imagebox and get info on the Imagebox about the unit.  My website on this project is at http://www.jarnath.freeservers.com
0
VingamelAuthor Commented:
I did find that dragging and droppping an imagebox onto an imagebox works fine.
0
VingamelAuthor Commented:
Also, forgot to note....why am I using an imagebox?  Because I can set its background to transparent
0
Bob LearnedCommented:
Another option would be to place an image box inside the picture box control that would be a child control.  When you drop the image box onto the picture box, then set the picture of the image control in the picture box to the Source.Picture.
0
VingamelAuthor Commented:
That will not be feasible, I think because there could be dozens of imageboxes at a time.  I don't know, maybe I am giving up too early on bitblting the units to the picBack instead of dealing with slews of imageboxes (eating up memory and response time).  In any case, you have answered my question, I just think I went down a dead-end alley this time.  Thanks a gob!!!
--Vingamel
http://www.jarnath.freeservers.com
0
Bob LearnedCommented:
I couldn't imagine that if you made a control array of image boxes that there would be that much of a performance hit.  

On the other hand, hundreds would probably start to affect the speed.
0
VingamelAuthor Commented:
I might try it out and see what happens.  Thanks again!
0
VingamelAuthor Commented:
I might try it out and see what happens.  Thanks again!
0
VingamelAuthor Commented:
Hey, the child imagebox idea works great.  Now I have a problem with your original solution...

Private Sub picBack_DragDrop(Source As Control, X As Single, Y As Single)
    If picBack.PSet(X, Y) = vbBlue Then '&HFFFF00 Then
        imgChild.Move X - 16, Y - 16
        imgChild.ZOrder (0)
        imgChild.Picture = Image1.Picture
    End If
End Sub

This gives me an error message, Argument Not Optional.  Why is this?
0
Bob LearnedCommented:
What line is giving you the error?
0
VingamelAuthor Commented:
I figured it out....Point should be used instead of PSet.  Thanks for all your help.

Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)

   If Picture1.Point(X, Y) = vbBlue Then
   End If
   
End Sub
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.