Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Rufus
  • *Experts*
Posted
You need to set grph to an instance of a Graphics object. For example;
Dim grph As System.Drawing.Graphics = Me.CreateGraphics

would use the graphics object of the form.

  • *Experts*
Posted
It doesn't surprise me that you can't see the line, since the start point and end point are at the same point (10, 10). Try changing the coordinates.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...