?
Solved

Detect color of pixel on picture box

Posted on 1999-11-16
15
Medium Priority
?
177 Views
Last Modified: 2010-05-02
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?
0
Comment
Question by:Vingamel
  • 9
  • 6
15 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 200 total points
ID: 2211601
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
 
LVL 1

Author Comment

by:Vingamel
ID: 2211989
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 2212007
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 2212011
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
 
LVL 1

Author Comment

by:Vingamel
ID: 2212036
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
 
LVL 1

Author Comment

by:Vingamel
ID: 2212039
I did find that dragging and droppping an imagebox onto an imagebox works fine.
0
 
LVL 1

Author Comment

by:Vingamel
ID: 2212045
Also, forgot to note....why am I using an imagebox?  Because I can set its background to transparent
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 2212083
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
 
LVL 1

Author Comment

by:Vingamel
ID: 2212116
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 2212130
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
 
LVL 1

Author Comment

by:Vingamel
ID: 2212135
I might try it out and see what happens.  Thanks again!
0
 
LVL 1

Author Comment

by:Vingamel
ID: 2212138
I might try it out and see what happens.  Thanks again!
0
 
LVL 1

Author Comment

by:Vingamel
ID: 2212471
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 2213947
What line is giving you the error?
0
 
LVL 1

Author Comment

by:Vingamel
ID: 2214559
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month5 days, 12 hours left to enroll

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question