tags:

views:

23

answers:

1

Hi all,

I would like to define regions on an image. Let's assume that I have the map of USA as image and when the mouse hovers one of the states, the message box will prompt the name of the state. In flash, each states are sliced and defined as a region. How an image can be sliced in WPF?

Thanks.

A: 

Assuming your map is drawn onto a WPF Canvas at the origin (0,0), that exists on the MainWindow of a new WPF project, what you could do is this:

1) In the codebehind file MainWindow.cs, create a Dictionary of "hitboxes" that define square regions on the map, and the relevant US state name.

2) Create an event handler for when the mouse moves over your Canvas. This event handler will give you the coordinates of the mouse.

3) Search the Dictionary to see which entry contains your current mouse coordinate, and retrieve the state name from the entry (if their is one).

This is pretty broad but without code examples of what you're trying to do it's at least a start.

bufferz
Hi,Thank you for your answer. I will try that. By the way, does searching the Dictionary for each mouse events introduce performance overhead?
bohemistanbul
It will probably be perfectly fast enough, I've done something similar with mouse hitboxes and lots of hitboxes, it worked well.
bufferz