Help interpreting this error

P

PJC

Trying to execute to following statement on vb.net for the pocketPC

Dim g As Graphics = somecontrol.CreateGraphics()

g.DrawRectangle(New Pen(Color.Red), 0, 0, 100, 100)

I get this error

An unhandled exception of type 'System.NotSupportedException' occurred in
System.Windows.Forms.dll

Additional information: NotSupportedException

it appears to be in the Color structure, and I suspect the library is not
available on the Toshiba e740 I am using.

Can someone please explain

Regards
 
P

PJC

The somecontrol object is a control on the form

the Statement
Dim curPen As New Pen(Color.Red)

also fails with the same message

Regards
-----------------------------------------------------
 
P

PJC

the control was a Panel control in the form_onpaint event

The code works if I connect it to a button click event and use
me.creategraphics()

regards

Peter
 
T

Tim Wilson

the control was a Panel control
The Panel control does not support the CreateGraphics call, only Control (a
basic control class) and Form do. Panel will throw a "NotSupportedException"
as you have found out.
The code works if I connect it to a button click event and use
me.creategraphics()
Yes. This will work becase CreateGraphics is being called against the Form
object (Me).

I suspect that you thought that the error was on the line after the line
making the CreateGraphics call as the next line is highlighted, in green (at
least for me), when an exception is throw and not caught by the app. So if
you had:

1. Dim g As Graphics = somecontrol.CreateGraphics()
2. g.DrawRectangle(New Pen(Color.Red), 0, 0, 100, 100)

Line 2 would be highlighted after the exception even though the exception
was caused by line 1. Confusing sometimes...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top