robbremington Posted January 6, 2003 Posted January 6, 2003 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 Quote
*Experts* Bucky Posted January 6, 2003 *Experts* Posted January 6, 2003 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] Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
robbremington Posted January 6, 2003 Author Posted January 6, 2003 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 Quote
*Experts* Bucky Posted January 6, 2003 *Experts* Posted January 6, 2003 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 Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
robbremington Posted January 6, 2003 Author Posted January 6, 2003 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: Quote
*Experts* Volte Posted January 6, 2003 *Experts* Posted January 6, 2003 The correct line is System.Windows.Forms.PaintEventArgs. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.