paint question

  • Thread starter Thread starter WStoreyII
  • Start date Start date
W

WStoreyII

i am using this code to try to paint a line on my form and it wont work i
get an object not set to a reference error

Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)

Dim formGraphics As System.Drawing.Graphics

formGraphics = Me.CreateGraphics()

formGraphics.DrawLine(myPen, 0, 0, 200, 200)

myPen.Dispose()

formGraphics.Dispose()



what is wrong

thanks for the help

WStoreyII
 
the load event i am trying to create a line?
can you only use it from with in certain events

WStoreyII
 
WStoreyII,
I would paint in the Paint event itself. This way if another form moves over
the top of your form, your form will be repainted correctly when it is
redisplayed.

I have not tried it, I don't think enough of the form is created in the Load
event for painting to occur correctly.

Note the Paint event has Graphics object to use in the PaintEventArgs
parameter, no need for CreateGraphics & Graphics.Dispose.

Hope this helps
Jay
 
Hi,

In addition to Jays comments. Anything you draw in the load event
will get erased when the form paints itself.

Ken
 
Back
Top