日期:2014-05-18 浏览次数:21081 次
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
int gridSize = 20;
for (int i = 0; i * gridSize < ClientSize.Width; i++)
{
e.Graphics.DrawString(i.ToString("00"), Font, Brushes.Black,
i * gridSize - 5, 0);
e.Graphics.DrawLine(Pens.Gray, i * gridSize, gridSize,
i * gridSize, ClientSize.Height);
}
for (int i = 0; i * gridSize < ClientSize.Height; i++)
{
e.Graphics.DrawString(i.ToString("00"), Font, Brushes.Black, 0,
i * gridSize - 5);
e.Graphics.DrawLine(Pens.Gray, gridSize, i * gridSize,
ClientSize.Width, i * gridSize);
}
for (int i = 0; i < points.Length; i++)
e.Graphics.DrawEllipse(Pens.Red,
(points[i].X + 1) * gridSize - 3, (points[i].Y + 1) * gridSize - 3,
6, 6);
for (int i = 0; i < groups.Count; i++)
{
int minX = int.MaxValue, minY = int.MaxValue,
maxX = int.MinValue, maxY = int.MinValue;
for (int j = 0; j < groups[i].Count; j++)
{
Point p = groups[i][j];
minX = p.X < minX ? p.X : minX;
minY = p.Y < minY ? p.Y : minY;
maxX = p.X > maxX ? p.X : maxX;
maxY = p.Y > maxY ? p.Y : maxY;
}
Rectangle r = Rectangle.FromLTRB(
(minX + 1) * gridSize - 5, (minY + 1) * gridSize - 5,
(maxX + 1) * gridSize + 5, (maxY + 1) * gridSize + 5);
e.Graphics.DrawRectangle(Pens.Blue, r);
e.Graphics.DrawString(i.ToString(), Font, Brushes.Black, r);
}
}
private const int pointCount = 100;
private Point[] points = new Point[pointCount];
private bool[] scans; // 是否计算过
private List <List <Point>> groups = new List <List <Point>>();