Jump to content

Creating polygons in pictureBox to get seperate mouse events (like a imagemap)

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
gaylo565

gaylo565

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 268 posts
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.

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

        }


#2
gaylo565

gaylo565

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 268 posts
Never Mind...Forgot to use a graphics path. For any one wondering that is how I got it to work

#3
FlashM

FlashM

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
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?

#4
gaylo565

gaylo565

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 268 posts
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
FlashM

FlashM

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
What does this location represent? Coordinate (lon, lat), some address, ...???

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Probably longitude and latitude, or the xy coordinates.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
gaylo565

gaylo565

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 268 posts
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.