|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionI noticed a few requests on various newsgroups for an image map control which could be used in a Windows Forms application. I had not worked much with the System.Drawing namespace, so I decided to give it a try. This control is the result. How It WorksThe control uses a standard The bulk of the logic is in the private private int getActiveIndexAtPoint(Point point)
{
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
System.Drawing.Drawing2D.GraphicsPathIterator iterator =
new System.Drawing.Drawing2D.GraphicsPathIterator(_pathData);
iterator.Rewind();
for(int current=0; current < iterator.SubpathCount; current++)
{
iterator.NextMarker(path);
if(path.IsVisible(point, this._graphics))
return current;
}
return -1;
}
How To Use ItYou can add this control to your toolbox just as you would any other .NET control. Once, added, simply drag-and-drop an
instance of the control onto your form. Use the Once you've added the control to your form, you can begin to call the various Here is the code required to define an HTML image map using the image in the first screenshot: <!--Text BUTTON-->
<area shape="rect" coords="140,20,280,60">
<!--Triangle BUTTON-->
<area shape="poly" coords="100,100,180,80,200,140">
<!--Face BUTTON-->
<area shape="circle" coords="80,100,60">
Here are the equivalent regions defined using this control: this.imageMap1.AddRectangle("Rectangle", 140, 20, 280, 60);
this.imageMap1.AddPolygon("Polygon", new Point[] {new Point(100, 100),
new Point(180, 80), new Point(200, 140)});
this.imageMap1.AddElipse("Ellipse", 80, 100, 60);
The control will raise an event - That's it! I hope this meets the needs of those who had requested an image map control for use in a Windows Forms application. Comments and requests are welcome.
|
||||||||||||||||||||||