Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Help! I'm 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�s no line control in NET and I can�t get this code to show anything on the form:

 

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.Red, 1)

Me.CreateGraphics.DrawLine(pen, 1000, 1000, 1000, 1000)

pen.Dispose()

End Sub

  • *Experts*
Posted

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 Form's Paint event and create a new Graphics object

from the PaintEventArgs passed to it, then draw to that.[/edit]

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

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 .

Where's 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

  • *Experts*
Posted

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.

 

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

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

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:

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...