views:

36

answers:

1

Hi All,

I am trying to write a simple program that lets me overlay a dot on top of an image when the image is clicked. I can save the X and Y data back to my database but then I will want to be able to call that information back at a later date and overlay the dots again via code unlike the first time when the user had to click the image.

I have got as far as capturing the X and Y of the click no problem but I am having trouble finding examples specifically for what I am trying to do. All of the examples online seem to be for saving the image with the added graphic but I dont need to do that as it will be the same image every time.

Once I can do this, I also need to work out a way that I can detect what area of the image has been clicked. The areas I need to mark out vary in shape and size so I need to try and work out a way to 'map' these areas and then cross reference with the co-ordinates of the users click (I assume that I may need to do some clever geometry stuff for that?)

If anyone has any suggestions of what subjects/classes/methods etc to research for either of my queries, I would very greatful.

Thanks in advance,

James

A: 

You can use the System.Drawing namespace to achieve this.

Create a control and override OnPaint and OnPaintBackground. Store your clicks in a List

  • In OnPaintBackground, draw the image using DrawImageUnscaled using the graphics object which is passed to you as a parameter.

  • In OnPaint, loop through your points array and call graphics.FillElipse or similar to draw a little dot.

Because this isnt a retained mode graphics system, you need to keep drawing these items so this may not suit a large number of dots. In that case, you can create an in memory bitmap and get a graphics drawing object using graphics.FromImage.

James Westgate
Hi James, thanks for your quick reply! I knew i'd have to be going down the system.drawing route but I am unfarmiliar with 'creating a control and overriding it' - please could you explain a bit further? Also - I assume I would use a picture box to display the image? Where does all my code need to sit / fire from - a picturebox event? Sorry - I'm not a complete novice but I have never worked with images this way in C#.
Jimbo James
What we are doing is basically writing a picturebox control with some added functionality. Its best to inherit straight from Control unless you want to use scrolling. The following should get you started: http://ondotnet.com/pub/a/dotnet/2002/03/18/customcontrols.html
James Westgate