Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all
i try to use image such as map , when i click on map i do some actions .,,
the question is how can i use this map as button without using button background image ?
because i need to display this map only with its borders not map on button ?
please help
Posted

If I understand what you want you'ld like to have an action associated with certain portions of the map ?

In that case you need to put the map in a panel eg. and use the onmousedown/up events to capture the mouse coordinates, with that you can determin where on the map, the user click. Additionally you can use the mouseover event to highlight that region with a circle, rectangle, ,... or something. (Use the Graphics object and pass the panel's handle)

It is really not that hard as it sounds and MSDN has some good examples.

Hope this helps.
 
Share this answer
 
There isn't the direct equivalent of an image map in winforms. There is a workaround that lets you emulate it:

  1. Hook into the control hosting the image's MouseUp event
  2. In the event handler, get the position of the mouse and react to it/li>


e.g. something like:
C#
private void whatever_MouseUp(Object sender, MouseEventArgs e)
{
    Rectangle rect = new Rectangle(0, 0 50, 50);  //this is rectangle you want clickable 
    if (rect.Contains(e.Location))
    {
        //Do whatever
    }
}



You are probably going to have multiple rectangles - I suggest storing them in a Dictionary objects (to prevent duplicates - you will have to do extra work to avoid overlapping areas), the value would be a the delegate method that is called. If you are going to use more complex shapes then you can't use the Rectangle object - the principle stands, but you'll have to come up with something yourself, though I dare say a quick Google would help.
 
Share this answer
 
v2
There are several ways you could approach this, but you need to clarify your goals.

0. is the structure of the zones you want "active:" i.e., to behave like a "button," regular/tiled so that you can easily calculate which area is "hit" using mathematics based on the Point where the MouseDown event occurs ? Example: a structure like a chessboard.

1. is there more than one area in the map you want active ?

2. are the areas you want active rectangular, or circular, or, complex areas defined by irregular paths (regions) ?

3. do you want some kind of visible indicator to appear on the map when the mouse moves over an active area ?

4. do you want the end-user at run-time to create/edit active zones, or, are they all pre-calculated in code in your application ?

Depending on your answer to these questions, solutions range from simple to complex.

Why don't you get some ideas by studying this article on CP: "C# Windows Forms ImageMap Control:" [^]. And, search CP for "ImageMap" to get other ideas.

If all your active areas are rectangular, and you do not need some form of overlay to pop-up when the mouse is over an active area, and all active areas are created by you at design-time, I have a simple "quick and dirty" solution I'm willing to post ... if you clarify your goals by answering the questions above.
 
Share this answer
 
you can put in div like this...and call onclick javascript function

Javascript

JavaScript
function AlertMessage()
{
//Do your operation 

}


HTML

HTML
<div onclick="AlertMessage()">
    
</div>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900