The application that I’m working on is going to be used to create charts of data contained in a database. Right now objects on the chart are manipulated using a “control panel” – essentially a list of objects and a PropertyGrid to edit values. The users would also like to be able to interact with the objects using mouse interactions – things like grabbing the corner of the chart and dragging to expand/contract it, clicking on a number and getting a text box to edit it, or right clicking on something to get a menu of possible interactions.
The chart is being drawn with GDI+ on a metafile (a requirement) which is then drawn on a user-drawn form.
I’m not really sure how to implement this. I’ve had a couple ideas:
- Create some custom controls that get overlaid on the chart graphic. Each control could be associated with a specific object or property of an object on a chart, and would update those values depending on how the user interacted with it.
- Just keep track of where objects are located, and when a user does something with the mouse, run through the list and figure out which object is supposed to be at the mouse location, and go from there.
I’m interested in how you guys would implement this and would really appreciate some suggestions. Thanks!
A good method for hit detection: have another off-screen image. draw every clickable object on this image with a unique color. You have to disable anti-aliasing. When user clicks get the color at that point from the off-screen image and determine the object. If you have a list of objects you can use object index as color. This method will handle hit detection of irregular shaped objects but will be a bit slower.
PS. Using controls will be slower than this.