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

NotSupportedException when CreateGraphics

4 views
Skip to first unread message

Kempton

unread,
May 14, 2004, 1:21:02 AM5/14/04
to
I would like to create a picturebox or panel that I can draw a graph on it. I did it by creating a class which inherits Panel (I tried PictureBox as well) and create a graphics in it by:

Private g as Graphics = Me.CreateGraphics

Although its syntax is correct, it give me System.NotSupportedException when I run it. How can I soft the problem?

Tim Wilson UNDERSCORE AT PERIOD

unread,
May 14, 2004, 1:30:15 AM5/14/04
to
"Only the Control and Form classes support Control.CreateGraphics()."
http://wiki.opennetcf.org/ow.asp?CompactFrameworkFAQ%2FCreateGraphicsOnTextBox

You should try to use the OnPaint method override in your custom control.

--
Tim Wilson
.Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}
"Kempton" <anon...@discussions.microsoft.com> wrote in message
news:D6B535AA-32B8-48BA...@microsoft.com...

Tim Wilson UNDERSCORE AT PERIOD

unread,
May 14, 2004, 2:13:09 AM5/14/04
to
Code below.
 
Public Class MyPanel
  Inherits System.Windows.Forms.Panel
 
  Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    Dim p As New Pen(Color.Red)
    e.Graphics.DrawRectangle(p, 10, 10, Me.ClientRectangle.Width - 20, Me.ClientRectangle.Height - 20)
    p.Dispose()
  End Sub
End Class


--
Tim Wilson
.Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}
"Kempton" <anon...@discussions.microsoft.com> wrote in message news:636F7629-0040-4E9A...@microsoft.com...
> Thank you for your help? Can you tell me more details? For example, how can I draw a rectangle with the OnPaint method?
0 new messages