touble with Graphics

rufus

Active member
Joined
Jul 7, 2003
Messages
28
Location
Arlington,TX
I written a code in button click event as


Dim grph As System.Drawing.Graphics
Try
Dim pen As Pen
pen = New Pen(Color:=Color.Blue, Width:=1)
grph.DrawLine(pen, 10, 10, 10, 10)
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.OKCancel)
End Try


when Iam running,its giving error as

Object reference not set to an instance of object.
at grph.DrawLine(pen, 10, 10, 10, 10)


can any one can help.
 
You need to set grph to an instance of a Graphics object. For example;
Code:
Dim grph As System.Drawing.Graphics = Me.CreateGraphics
would use the graphics object of the form.
 
It doesnt surprise me that you cant see the line, since the start point and end point are at the same point (10, 10). Try changing the coordinates.
 
Back
Top