Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawing lines in VB.net 2

Status
Not open for further replies.

BadCook

Technical User
Sep 7, 2009
71
0
0
US
I am trying to move from VB6 to VB.net.
All the samples I've seen don't have the VB6 line tool in the tool box.
Lines in my programs are important. With VB6 one can draw a line on the graphic form by simply pointing to the end points, and then set the width property.
Can this tool be imported into VB.net?
Is there a version of VB.net that has it?
Any advice would be appreciated.
 
The drawing libraries in .Net are extensive.

This code snippet will get your started
Code:
    Private Sub Form3_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        e.Graphics.DrawLine(Pens.Red, 0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height)
    End Sub

But there is really a lot to read up on. You can have different types, widths and colors of pens and brushes. You can draw other objects than lines. You might want to double-buffer your graphics, etc.
 
If you want a design type control that allows lines and shapes drawing, take a look at the Microsoft Power Packs.


=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB.NET Programmer
 
Thanks RiverGuy
I pasted youi code and it works.
Not as handy as in VB6, but workable. I wonder why Microsoft didn't keep the VB6 line tool.
Now, do you have a suggestion as to how to control the width of the line?
 
Well, if I had the choice between a full fledged 2D drawing library or a couple of line/ellipse controls, I'd take the more feature-rich library. It's not difficult once you get the hang of it.

To change the width, change the width of your pen:
Code:
Dim CustomPen As New Pen(color.Black, 4)

Use your own Pen instance instead of the Pens.Red.
 
Thanks again, RiverGuy'
I appreciate your help very much.
I have a feeling the VB.net learning curve for me will be long and steep, but what the heck, whats heaven for?
 
The Frame tool in VB6 is missing in VB.net. How can I produce a Frame in VB.net?
Any help will be appreciated.
 

Frame is there (in VB.NET), but it is called GroupBox now.

The same happend to Option Buttons, they are Radio Buttons now.

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top