|
-
Feb 12th, 2003, 08:57 AM
#1
Thread Starter
Hyperactive Member
Lines/Shape Control
How to draw an line on a form in VB.NET?
In vb6 we had a simple Control for that... Anyone can tell me how?
There's a certain mystique when I speak, that you notice that it's sorta unique, cause you know it's me
-
Feb 12th, 2003, 09:32 AM
#2
New Member
First you create a pen object to draw the line with. Then you draw the line with the CreateGraphics.DrawLine method, sending the pen, starting and ending points as arguments.
Example:
VB Code:
Dim blackPen As New Pen(Color.Black)
CreateGraphics.DrawLine(blackPen, 0, 0, 50, 50)
/Sara
-
Feb 12th, 2003, 09:38 AM
#3
Frenzied Member
Be sure to import System.Darwing
then one simple way maybe this
VB Code:
Dim g As Graphics = Me.CreateGraphics
Dim p As Pen = New Pen(Color.Black)
g.DrawLine(p, 0, 0, 200, 200)
g.Dispose()
p.Dispose()
-
Feb 12th, 2003, 09:53 AM
#4
Thread Starter
Hyperactive Member
Thanks for the reaction, but none of the examples work... There aren't any lines drawn on my form
/edit
Aargh, it does work... only in the Form_Paint Sub, or am i wrong?
Last edited by phrozeman; Feb 12th, 2003 at 09:59 AM.
There's a certain mystique when I speak, that you notice that it's sorta unique, cause you know it's me
-
Feb 12th, 2003, 10:02 AM
#5
Frenzied Member
Maybe you are putting the code in form load event, I dont know y it does not draw in form load, I will tell you if i find the reason.
-
Feb 12th, 2003, 10:09 AM
#6
Frenzied Member
Ok, I find out the reason,
When you draw a line in form load event, at first the line is drwan then the form paints, so it earases the line. You should put it in onPaint event if you want to draw the line when form loads.
VB Code:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
e.Graphics.DrawLine(Pens.Black,0,0,50,50)
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|