How do you make certain areas of a PictureBox clickable?
I have an image (PictureBox) that I'm using in my main form which contains a background and a few icons. What I would like to be able to do is make certain portions of the image "clickable" (the icons) so that I can open different forms, depending on which portion of the image (icon) was clicked. The functionality that I'm looking for is similar to an HTML Image Map. I can accomplish this by breaking the image up, but that would be a real pain in the butt. I'm thinking another possibility is to use x/y coordinate ranges, but I'm not entirely sure how to make the coordinate ranges "clickable". Hopefully there is an easier way. Any suggestions? Thanks in advance.
Just Make 2 pictures in the same size, one for the Area Colors (picMap) and one for the Image (picUser), when you move in the picUser search the pixel color in the picMap, depending of the pixel color it the action that you will do in the click event.
Mikecrosoft.NET * If I stop to ask I will stop to learn
* Just I know that I don't know nothing
The way I would do it would be to break the picture up and use multiple picture boxes. It may be a pain to create, but it's easy to code.
Another possible way I can think of is determine the areas you want to be clickable and create a rectangle object with those bounds. Whenever the picturebox is clicked, determine whether the user clicked within one of the rectangles.
I think it'd be far easier to just break the image up, though.
I'm not sure I understand what you're suggesting. Do you create 2 PictureBox controls and stack them on top of one another? Do you by any chance have a sample form that I might be able to look at? In any event, I'll play around with it. I'm having a few other problems that I need to address first, like placing PictureBox controls on an MDI parent form. It seems that if any controls are placed on the MDI parent, they will overlap any child forms--which basically makes it useless for me to use "icons". I'm still searching for some kind of workaround for this. Attached is a screenshot of what I have so far (including the problem I'm having with my MDI container), so I know we are on the same page.
Mikecrosoft: Thanks for all your help. I got it working. Now all I need to do is figure out the MDI parent PictureBox issue. :P
Good luck! I have been trying to do that for ages, .
MDI Containers in .NET are weird. If you have a normal form, you could do this no worries:
Private Sub Form1_MouseDown(ByVal sender AsObject, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
MsgBox(e.X & ", " & e.Y)
Then based on the x and y, decide what was clicked.
You know what i reckon? If you aren't using the other MDI properties, such as window tiling, etc, use a normal form, and create a picture that makes it *look* like a container, and stop the other forms from being dragged outside the border of your fake MDI container.
Thanks for the suggestions. How would I go about stopping other forms from from being dragged outside of the fake MDI container? This is actually something I had considered earlier today, but wasn't sure how to go about doing it. The fake MDI container would be scalable, so I figured it would inefficient to always have to track the x/y coordinates of the container.