Converting Line Control to .NET drawline

robbremington

Member
Joined
Jan 6, 2003
Messages
17
Help! Im agitated attempting to convert a VB app from 6 to net!

The app generates a flowchart with boxes and lines from database coordinates, but there
 
The default unit mode for forms in VB.NET is Pixels, not Twips.
Drawing a line at the coords 1000, 1000 is probably way off the
form.

[edit]Also in VB.NET you need to persist the graphics, so put this
code in the Forms Paint event and create a new Graphics object
from the PaintEventArgs passed to it, then draw to that.[/edit]
 
I added a label to the form and changed the Drawline arguments to 200,300, 400, 500. When executed all I see is the label .
Wheres that pesky line?
Thanks for your help.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim pen As New Drawing.Pen(System.Drawing.Color.Black, 2)
Me.CreateGraphics.DrawLine(pen, 200, 300, 400, 500)
pen.Dispose()
End Sub
 
As I said before, you need to put that code in the Paint event of
the form and draw with a copy of the graphics object that is
passed in the PaintEventArgs.

Code:
Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.PaintEventArgs) Handles MyBase.Paint
  Dim pen As New Drawing.Pen(System.Drawing.Color.Black, 2)
  Dim g As Graphics = e.Graphics

  g.DrawLine(pen, 200, 300, 400, 500)

  pen.Dispose()
End Sub
 
Form1.vb reads:

Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
Inherits System.Windows.Forms.Form

-- Windows form designer generated code

Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.PaintEventArgs) Handles MyBase.Paint
Dim pen As New Drawing.Pen(System.Drawing.Color.Black, 2)
Dim g As Graphics = e.Graphics

g.DrawLine(pen, 200, 300, 400, 500)

pen.Dispose()
End Sub

!!!!But I get an error System.PaintEventArgs
"Type System.PaintEventArgs is not defined"
:confused:
 
Back
Top