private void pbField_MouseDown(object sender, MouseEventArgs e)
{
pbField.
//move the dot object to the mouse position and set the color so that it can be seen
pntDot.X = e.X;
pntDot.Y = e.Y;
pbField.Invalidate();
}
//create a point object to keep track of where the mouse is and where the point will be drawn
private Point pntDot = new Point();
private Pen pDraw = new Pen(Color.Green, 4);
private void pbField_Paint(object sender, PaintEventArgs e)
{
//create a dot object on panel 1 that can be moved around on mouse click
Graphics g = e.Graphics;
g.DrawEllipse(pDraw, pntDot.X, pntDot.Y, 4,4);
}
Creating polygons in pictureBox to get seperate mouse events (like a imagemap)
Started by gaylo565, Nov 27 2009 09:47 AM
6 replies to this topic
#1
Posted 27 November 2009 - 09:47 AM
I am developing an application for windows mobile devices and I am trying to create polygons within a picturebox so that I can have seperate Click events in the different polygon positions (Or at least send back a different dialog to the click method based on which polygon the mouse is in.) I could hard code it with a ton of if statements and create equations for each line in my polygons but this would be horribly tedious and I know there must be an easier way to do this. This is similar to the image map in asp but i cant find a property or object that allows me to do this with a picture box. any help would be appriciated. Here is the code for the Current MouseDown and Paint events for the pictureBox and they are working how I need them to.
|
|
|
#2
Posted 27 November 2009 - 09:57 AM
Never Mind...Forgot to use a graphics path. For any one wondering that is how I got it to work
#3
Posted 27 November 2009 - 09:59 AM
Tricky one :-) I have never been in need for something like that :-) It would be easier if I could imagine what you are trying to do.
But I love the solution from Google on how they determine if user clicked inside or outside the polygon and it goes something like this:
If you draw a horizontal line from point of click to the right edge of the screen and if this horizontal line crosses polygon line even times or odd times, you know if user clicked inside or outside the polygon.
Can you give some more info on what you are trying to do?
But I love the solution from Google on how they determine if user clicked inside or outside the polygon and it goes something like this:
If you draw a horizontal line from point of click to the right edge of the screen and if this horizontal line crosses polygon line even times or odd times, you know if user clicked inside or outside the polygon.
Can you give some more info on what you are trying to do?
#4
Posted 27 November 2009 - 10:09 AM
The graphics path doesnt seem to work in the mobile sdk and I am still searching for a solution. Then end goal is to have the user be able to select a location on the picture box and this would leave a dot in that location. Then if the user hits a submit button on the form, based on where the dot they had left was located I need the event to handle differently. Any help would be appriciated. Thx in advance
#5
Posted 27 November 2009 - 12:35 PM
What does this location represent? Coordinate (lon, lat), some address, ...???
#6
Posted 27 November 2009 - 07:51 PM
Probably longitude and latitude, or the xy coordinates.
#7
Posted 30 November 2009 - 07:28 AM
It represents the xy coordinates right now but I am flexible as far as how to get it done. As of right now I am simply coding equations for each line int the polygons and then making complex neseted logic to get it all to work properly. Now that I have this most of the way done I am not likely to switch to something new, but would still love to see a more efficient way of doing this.


Sign In
Create Account


Back to top









