Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > How do you make certain areas of a PictureBox clickable?


Reply
 
Thread Tools Display Modes
  #1  
Old 03-18-2004, 10:21 AM
MoMo's Avatar
MoMo MoMo is offline
Centurion
 
Join Date: Feb 2002
Location: San Antonio
Posts: 111
Cool 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.
__________________
|04D06F|²
Reply With Quote
  #2  
Old 03-18-2004, 11:06 AM
Mikecrosoft's Avatar
Mikecrosoft Mikecrosoft is offline
Mexican Coder
 
Join Date: Jun 2002
Location: Monterrey, N.L., Mexico
Posts: 2,793
Default

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
Reply With Quote
  #3  
Old 03-18-2004, 11:13 AM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,505
Default

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.
Reply With Quote
  #4  
Old 03-18-2004, 11:15 AM
Mikecrosoft's Avatar
Mikecrosoft Mikecrosoft is offline
Mexican Coder
 
Join Date: Jun 2002
Location: Monterrey, N.L., Mexico
Posts: 2,793
Default

My way of doing this allow you to create irregular forms. not rectangles only.

__________________
Mikecrosoft.NET
* If I stop to ask I will stop to learn
* Just I know that I don't know nothing
Reply With Quote
  #5  
Old 03-18-2004, 11:22 AM
Mikecrosoft's Avatar
Mikecrosoft Mikecrosoft is offline
Mexican Coder
 
Join Date: Jun 2002
Location: Monterrey, N.L., Mexico
Posts: 2,793
Default

Heres a sample
Attached Images
File Type: jpg User-Map.JPG (6.5 KB, 24 views)
__________________
Mikecrosoft.NET
* If I stop to ask I will stop to learn
* Just I know that I don't know nothing
Reply With Quote
  #6  
Old 03-18-2004, 11:36 AM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,505
Default

The picture says so much more than the words did. That's a pretty awesome approach that basically does what I suggested with the rectangles, only without the mess of having to guess coordinates.
Reply With Quote
  #7  
Old 03-18-2004, 11:39 AM
Mikecrosoft's Avatar
Mikecrosoft Mikecrosoft is offline
Mexican Coder
 
Join Date: Jun 2002
Location: Monterrey, N.L., Mexico
Posts: 2,793
Default

This idea I took it from the way of doing a Isometric field (Games).
__________________
Mikecrosoft.NET
* If I stop to ask I will stop to learn
* Just I know that I don't know nothing
Reply With Quote
  #8  
Old 03-18-2004, 03:23 PM
MoMo's Avatar
MoMo MoMo is offline
Centurion
 
Join Date: Feb 2002
Location: San Antonio
Posts: 111
Question ...

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.
Attached Images
File Type: jpg problem.jpg (33.0 KB, 17 views)
__________________
|04D06F|²
Reply With Quote
  #9  
Old 03-18-2004, 03:29 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

Probably the simplest way is to put IMAGE boxes on TOP of the picturebox. Then simply handle the click event of the IMAGE.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #10  
Old 03-18-2004, 04:18 PM
Mikecrosoft's Avatar
Mikecrosoft Mikecrosoft is offline
Mexican Coder
 
Join Date: Jun 2002
Location: Monterrey, N.L., Mexico
Posts: 2,793
Default

I did a sample for you, its simple but its the base.




Its the form only, you will need to add into a new project.
Attached Files
File Type: zip Sample Form.zip (16.7 KB, 19 views)
__________________
Mikecrosoft.NET
* If I stop to ask I will stop to learn
* Just I know that I don't know nothing
Reply With Quote
  #11  
Old 03-18-2004, 04:25 PM
Mikecrosoft's Avatar
Mikecrosoft Mikecrosoft is offline
Mexican Coder
 
Join Date: Jun 2002
Location: Monterrey, N.L., Mexico
Posts: 2,793
Default

Bill, I didn't see you for large time. May be I didn't see your posts , However, Hello Bill.
__________________
Mikecrosoft.NET
* If I stop to ask I will stop to learn
* Just I know that I don't know nothing
Reply With Quote
  #12  
Old 03-18-2004, 06:42 PM
MoMo's Avatar
MoMo MoMo is offline
Centurion
 
Join Date: Feb 2002
Location: San Antonio
Posts: 111
Thumbs up ...

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
__________________
|04D06F|²
Reply With Quote
  #13  
Old 03-18-2004, 09:48 PM
sgt_pinky's Avatar
sgt_pinky sgt_pinky is offline
Contributor
 
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 633
Default

Quote:
Originally Posted by MoMo
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:

Code:
Private Sub Form1_MouseDown(ByVal sender AsObject, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
	MsgBox(e.X & ", " & e.Y)
End Sub
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.

Seriously, this has caused much angst in my life
Reply With Quote
  #14  
Old 03-18-2004, 09:53 PM
MoMo's Avatar
MoMo MoMo is offline
Centurion
 
Join Date: Feb 2002
Location: San Antonio
Posts: 111
Thumbs up ...

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.
__________________
|04D06F|²
Reply With Quote
  #15  
Old 03-18-2004, 09:56 PM
sgt_pinky's Avatar
sgt_pinky sgt_pinky is offline
Contributor
 
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 633
Default

Another way that works in normal forms, but not MDI containers:

Code:
Private Sub Form1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles MyBase.Click
Dim x, y As Single
x = Me.MousePosition.X
y = Me.MousePosition.Y
MsgBox(x & ", " & y)
End Sub
They are weird man, i am tellin' ya

Edit: Here is a class worth looking at...
Windows.Forms.MdiClient.MousePosition()
Reply With Quote
Reply


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
picturebox as variable CrashDaddy Game Programming 10 03-08-2004 05:15 PM
How to make a PictureBox 'bounce' off of the edges? compuXP General 3 02-27-2004 06:30 PM
transparent picturebox cracklestudios Game Programming 1 01-31-2004 11:42 AM
How to make a mIRC DLL :D Kaluriel Tech Discussions 1 01-19-2004 10:04 AM
Picturebox and BitBlt gimpelzack General 1 05-16-2002 04:14 AM

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
 
 
-->