Line Drawing

ZeRon

New member
Joined
Nov 18, 2006
Messages
1
Programming Experience
3-5
hello
Im Just started Vb.Net Im used to work with vb classic , Im trying to draw a line , a simple line, in Vb.net but the problem is that im not finding a line tab in the components i found that the only way to do that is by writing a code , i found that very disturbing ,I mean vb classic is much easier for simple things like drawing a line or any other shape .
So am I missing something on drawing shapes ?
thank you
 
Well since there is no line control in vb.net, you will have to do a certain amount of drawing youself but it's easier just to create your own line control. Add a new custom control your project or create a separate control library project and add a reference to in in your application. Open that paint event handler in the custom control and add the following..



VB.NET:
pe.graphics.drawline(Pens.Black, convert.toint32(me.Width/2), Me.Top, Convert.toint32(Me.Width/2), Me.Bottom)

Add the following in the contructor..


VB.NET:
Mybase.SetStyle(ControlStyles.AllPaintingInWM_Paint,True)
Mybase.SetStyle(ControlStyles.OptimizedDoubleBuffer,True)
Mybase.SetStyle(ControlStyles.UserPaint,True)
Mybase.SetStyle(ControlStyles.ResizeRedraw,True)


There you go. Build the project, add the reference to your existing project and in the toolbox you will find your new line control. To can go on to add properties to change the color/width/style of the line, make it horizontal or diagonal. Anything you want really.
 
There are various simple things that were easier to do in VB6 but what VB.NET provides is a way to do something simple and something complex, which may have been all but impossible in VB6, in basically the same way. With the additional power of VB.NET comes more complexity by necessity. It's not necessarily much more complex though, and the methodology for things like drawing shapes and other effects is very powerful, very well defined and very well documented.
 
Back
Top