DrawString to PictureBox Got Exception VB.Net

I have a PictureBox on the Form. The Graphic object is getting from that PictureBox for drawing. I drew a string. Ran fine in emulator. However, when ran in
device with pocket pc platform, I got exception. There is no specific error.
How come ?
[253 byte] By [TanChenYee] at [2007-12-16]
# 1
Post the code you are using. It may make it easier to figure out the problem.
Mark Arteaga
.NET Compact Framework MVP
http://www.neotericsdc.com | http://blog.markarteaga.com
MarkArteaga_MVP at 2007-9-9 > top of Msdn Tech,Smart Device Development,.NET Compact Framework...
# 2

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

Dim grpDraw As Graphics = PictureBox1.CreateGraphics()

grpDraw.DrawString("123", New Font("Courier New", 8.25, FontStyle.Regular), New SolidBrush(Color.Black), 5, 5)

End Sub

When I clicked on the button in pocket pc device. I got an exception of NotSupportedException. I have .Net Compact 2.0.

TanChenYee at 2007-9-9 > top of Msdn Tech,Smart Device Development,.NET Compact Framework...
# 3

There is something very wrong in your description. As far as I know, PcitureBox.CreateGraphics is not supported so I am having trouble accepting your assertion that this code works in the emulator; can you try that again please?

If you insist that it works in the emulator then I'd check that the PPC you are using is 2003 and above since CF 2.0 is not supported on earlier versions (2000 or 2002). It also helps to use breakpoints so you can tell the forum exactly which statement causes the exception.

I suspect you'll find this code doesn't work anywhere. If you change the first statement to use Me.CreateGraphics then it will work but your "123" text will be drawn on the form, not the picturebox.

To draw on the picturebox, handle its Paint event and put the code in there; again change the first statement to be grpDraw = e.Graphics

Good luck!

Cheers
Daniel

DanielMoth at 2007-9-9 > top of Msdn Tech,Smart Device Development,.NET Compact Framework...