Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

System.Windows.Forms.ControlPaint.DrawGrid equivalent?

2 views
Skip to first unread message

Wade

unread,
Mar 14, 2006, 1:41:38 PM3/14/06
to
Hi all,

Is there an equivalent to the System.Windows.Forms.ControlPoint.DrawGrid in
the .NET 2.0 Compact Framework? I'd like to find a way to easily draw a
grid on my form.

Thanks,

Wade


Tim Wilson UNDERSCORE AT PERIOD

unread,
Mar 14, 2006, 7:37:39 PM3/14/06
to
The ControlPaint class does not exist in the CF. Your best bet is to draw a
sample of the grid onto a Bitmap and then use a TextureBrush to splash this
image over and over again to get the grid look. You can add the following
method to your form class definition and then tweak it as you see fit.

protected override void OnPaintBackground(PaintEventArgs e)
{
using (Bitmap sample = new Bitmap(16, 16))
{
using (Graphics prep = Graphics.FromImage(sample))
{
prep.Clear(this.BackColor);
}
sample.SetPixel(8, 8, Color.Black);
using (TextureBrush brush = new TextureBrush(sample))
{
e.Graphics.FillRectangle(brush, this.ClientRectangle);
}
}
}

And, of course, you'll get even better performance if you create the
TextureBrush only when necessary. In other words, you may also want to cache
the TextureBrush so that you don't need to create it everytime the method is
called.

--
Tim Wilson
.NET Compact Framework MVP

"Wade" <wwegner23NOEMAILhotmail.com> wrote in message
news:u6obub5R...@TK2MSFTNGP11.phx.gbl...

Jim

unread,
Mar 14, 2006, 11:04:35 PM3/14/06
to
Tim,

Isn't there a way to do owner draw in CF 2.0? I thought I heard it was
new for CF 2.0.

Tim Wilson UNDERSCORE AT PERIOD

unread,
Mar 15, 2006, 12:27:59 AM3/15/06
to
I believe that the poster is asking about drawing an actual array of "dots",
similar to the grid that you may see on the form at design-time within the
forms designer. Are you wondering about the DataGrid?

--
Tim Wilson
.NET Compact Framework MVP

"Jim" <jimp...@mobiledynamo.com> wrote in message
news:1142395475.6...@i40g2000cwc.googlegroups.com...

Wade

unread,
Mar 15, 2006, 6:21:50 PM3/15/06
to
Awesome, thanks Tim.

"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
news:ukPCwi8R...@TK2MSFTNGP09.phx.gbl...

0 new messages