views:

137

answers:

1

I have converted postcode boundary polygons to point data (point[] for each polygon) from GIS Shape Files.

I am wanting to show this in a c# windows forms application.

I have managed to show this using the System.Drawing (GDI+) DrawPolygon() method.

Graphics g = this.CreateGraphics();
Pen pen = new Pen(Color.Black);
Brush brush = new SolidBrush(Color.FromArgb(255,255,o));

PointF[] ptr = { point data here };

g.FillPolygon(brush, ptr);
g.DrawPolygon(pen, ptr);

Is it possible to add events to a drawn polygon? If so how do I do this for individual polygons. For example, click on a postcode polygon and a messagebox shows information about the postcode.

Secondly, would it be easier to make a custom control inheriting the winforms panel. Is there a way to shape the border of a winforms panel control using a set of points?

Postcode objects are serialised and stored in the filesystem.

+2  A: 

Using custom shaped controls will require a bit of tweaking, but when you get it right, Windows will take care of the hit tests for you.

If you choose to use the GDI+ approach, you'll want to draw the polygons in the Paint event handler of your form, and handle the MouseDown event to figure out in which polygon the coordinates fall into.

A "drawn" polygon is no longer an object, so there is no way to add events to it. You could however make a Polygon class with a method void PaintMe(Graphics g) and a method bool HitTest(int x, int y) so you have all logic in one class.

deltreme
Thanks, I created a custom user Control, and used the Region field and GDI+ Graphics path to create the custom border. HitTest is handled by Windows.
JD