1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Microsoft.VisualBasic;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
private System.Drawing.Graphics g;
private System.Drawing.Pen pen1 = new System.Drawing.Pen(Color.Blue, 2F);
GraphicsPath path = new GraphicsPath();
public Form1()
{
InitializeComponent();
g = pictureBox1.CreateGraphics();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
List <Point> point = new List<Point>();
Point[] Points =
{
new Point(10, 10),
new Point( 10, 110),
new Point(110, 110),
new Point(110, 10),
new Point(50, 50),
new Point(50, 60),
new Point(60, 60),
new Point(60, 50)
};
Point test = new Point (65,65);
List<int> index =new List<int>();
index.Add(0);
index.Add(3);
index.Add(4);
index.Add(7);
for (int i=0;i <index.Count;i+=2)//parcourt la list "index" avec les bornes des polygones
{
if (point.Count != 0)
{
while (point.Count != 0)
point.RemoveAt(0);
}
for (int j = index[i]; j <= index[i + 1];j++ )
{
point.Add(Points[j]); // point = coordonnées des sommets des polygones
}
path.StartFigure();
path.AddPolygon(point.ToArray());
//g.DrawPolygon(pen1,point.ToArray());
path.CloseFigure();
g.DrawPath(pen1, path);
//if (path.IsVisible(test))
// MessageBox.Show("ok");
}
if (path.IsVisible(test))
MessageBox.Show("ok");
}
}
} |
Partager