W
Wade
Hey all,
I am drawing a grid on my windows form -- however, I wonder if the way I'm
doing it isn't the best, as it seems to take awhile to create the grid. Any
thoughts?
private void DrawGrid()
{
DrawGridBoundary();
int Width = FormWidth;
int Height = FormHeight - pnlControls.Height;
int NumberOfCols = Width / GridSize;
int NumberOfRows = Height / GridSize;
for (int i = TopLeft.Y; i < (BottomRight.Y - GridSize); i = i +
GridSize)
{
for (int j = TopLeft.X; j < (BottomRight.X - GridSize); j =
j + GridSize)
{
DrawGridPoint(GridSize + j - 1, GridSize + i);
}
}
}
private void DrawGridBoundary()
{
int Width = FormWidth;
Graphics gfx = this.CreateGraphics();
Pen p = new System.Drawing.Pen(System.Drawing.Color.Black, 1);
Rectangle rect = new Rectangle(TopLeft.X, TopLeft.Y,
BottomRight.X - TopLeft.X, BottomRight.Y - TopLeft.Y);
gfx.DrawRectangle(p, rect);
}
private void DrawGridPoint(int X, int Y)
{
Graphics gfx = this.CreateGraphics();
Rectangle rect = new Rectangle(X, Y, 1, 1);
System.Drawing.Pen p = new
System.Drawing.Pen(System.Drawing.Color.Gray);
gfx.DrawRectangle(p, rect);
}
Thanks for the help!
I am drawing a grid on my windows form -- however, I wonder if the way I'm
doing it isn't the best, as it seems to take awhile to create the grid. Any
thoughts?
private void DrawGrid()
{
DrawGridBoundary();
int Width = FormWidth;
int Height = FormHeight - pnlControls.Height;
int NumberOfCols = Width / GridSize;
int NumberOfRows = Height / GridSize;
for (int i = TopLeft.Y; i < (BottomRight.Y - GridSize); i = i +
GridSize)
{
for (int j = TopLeft.X; j < (BottomRight.X - GridSize); j =
j + GridSize)
{
DrawGridPoint(GridSize + j - 1, GridSize + i);
}
}
}
private void DrawGridBoundary()
{
int Width = FormWidth;
Graphics gfx = this.CreateGraphics();
Pen p = new System.Drawing.Pen(System.Drawing.Color.Black, 1);
Rectangle rect = new Rectangle(TopLeft.X, TopLeft.Y,
BottomRight.X - TopLeft.X, BottomRight.Y - TopLeft.Y);
gfx.DrawRectangle(p, rect);
}
private void DrawGridPoint(int X, int Y)
{
Graphics gfx = this.CreateGraphics();
Rectangle rect = new Rectangle(X, Y, 1, 1);
System.Drawing.Pen p = new
System.Drawing.Pen(System.Drawing.Color.Gray);
gfx.DrawRectangle(p, rect);
}
Thanks for the help!