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!

Re: Drawing a grid on the form by Tim

Tim
Tue Mar 14 12:29:25 CST 2006

Take a look at the static DrawGrid method of the ControlPaint class.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolpaintclassdrawgridtopic.asp

--
Tim Wilson
.NET Compact Framework MVP

"Wade" <wwegner23NOEMAILhotmail.com> wrote in message
news:uIwek44RGHA.4752@TK2MSFTNGP10.phx.gbl...
> 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!
>
>



Re: Drawing a grid on the form by Wade

Wade
Tue Mar 14 12:40:01 CST 2006

Okay ... now to make this more difficult.

How about within the .NET Compact Framework? :)

"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
news:uXyt%23U5RGHA.5156@TK2MSFTNGP10.phx.gbl...
> Take a look at the static DrawGrid method of the ControlPaint class.
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolpaintclassdrawgridtopic.asp
>
> --
> Tim Wilson
> .NET Compact Framework MVP
>
> "Wade" <wwegner23NOEMAILhotmail.com> wrote in message
> news:uIwek44RGHA.4752@TK2MSFTNGP10.phx.gbl...
>> 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!
>>
>>
>
>



Re: Drawing a grid on the form by Tim

Tim
Tue Mar 14 18:42:07 CST 2006

ControlPaint is a very cool class; however, it's not present in the Compact
Framework. See the answer that I posted to your question in the CF
newsgroup.
http://groups.google.com/group/microsoft.public.dotnet.framework.compactframework/browse_thread/thread/560c9b88bb9129a8/64c297a321e6b48d?hl=en#64c297a321e6b48d

--
Tim Wilson
.NET Compact Framework MVP

"Wade" <wwegner23NOEMAILhotmail.com> wrote in message
news:%23d5u0a5RGHA.4792@TK2MSFTNGP14.phx.gbl...
> Okay ... now to make this more difficult.
>
> How about within the .NET Compact Framework? :)
>
> "Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
> news:uXyt%23U5RGHA.5156@TK2MSFTNGP10.phx.gbl...
> > Take a look at the static DrawGrid method of the ControlPaint class.
> >
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolpaintclassdrawgridtopic.asp
> >
> > --
> > Tim Wilson
> > .NET Compact Framework MVP
> >
> > "Wade" <wwegner23NOEMAILhotmail.com> wrote in message
> > news:uIwek44RGHA.4752@TK2MSFTNGP10.phx.gbl...
> >> 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!
> >>
> >>
> >
> >
>
>



Re: Drawing a grid on the form by Wade

Wade
Wed Mar 15 17:21:38 CST 2006

Awesome, thanks Time.

"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
news:%235bDPl8RGHA.2536@tk2msftngp13.phx.gbl...
> ControlPaint is a very cool class; however, it's not present in the
> Compact
> Framework. See the answer that I posted to your question in the CF
> newsgroup.
> http://groups.google.com/group/microsoft.public.dotnet.framework.compactframework/browse_thread/thread/560c9b88bb9129a8/64c297a321e6b48d?hl=en#64c297a321e6b48d
>
> --
> Tim Wilson
> .NET Compact Framework MVP
>
> "Wade" <wwegner23NOEMAILhotmail.com> wrote in message
> news:%23d5u0a5RGHA.4792@TK2MSFTNGP14.phx.gbl...
>> Okay ... now to make this more difficult.
>>
>> How about within the .NET Compact Framework? :)
>>
>> "Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in
>> message
>> news:uXyt%23U5RGHA.5156@TK2MSFTNGP10.phx.gbl...
>> > Take a look at the static DrawGrid method of the ControlPaint class.
>> >
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolpaintclassdrawgridtopic.asp
>> >
>> > --
>> > Tim Wilson
>> > .NET Compact Framework MVP
>> >
>> > "Wade" <wwegner23NOEMAILhotmail.com> wrote in message
>> > news:uIwek44RGHA.4752@TK2MSFTNGP10.phx.gbl...
>> >> 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!
>> >>
>> >>
>> >
>> >
>>
>>
>
>