putting a line on my form

  • Thread starter Thread starter cj
  • Start date Start date
C

cj

Back in VB4 there was a line tool in my toolbox that allowed me to put a
decorative line on the form somewhere. Does VB.net 2003 offer this?
It's not in the toolbox and I can't find it in the list to add to the
toolbox.
 
cj said:
Back in VB4 there was a line tool in my toolbox that allowed me to put a
decorative line on the form somewhere. Does VB.net 2003 offer this?

No, it doesn't.
 
I might do that, but I might use GDI graphics. It just seems overly
complicated to use GDI graphics for 1 horizontal line. I'm thinking
I'll need to put it in the form paint event too. I wonder which way
requires the least resources from the pc, a label 1 pixel high or a gdi
graphic generated line?
 
Guy's advice looks and works nice. It's a shame we have to fool VB into
making a line using a label. I've been reading and GDI seems to be the
way they want us to make lines now.
 
cj,

I am glad you write that, I had already written this is a little bit other
way somewhere else.

Cor
 
Cor Ligthert said:
cj,

I would take the advice from guy, using GDI makes it slow.

Cor

How so? I see adding a label to the form would be slower because the label
uses GDI to draw all 4 borders, while using GDI, you just draw one line...

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)

e.Graphics.DrawLine(Me.ForeColor, 100, 100, 300, 100)
End Sub

Code not tested :)

HTH,
Mythran
 
Mythran,

How about giving me that line in a manner that can be pasted into
Form1_Load or Form1_Paint event? I'd like to play with it.
 
Mythran,

How about giving me that line in a manner that can be pasted into
Form1_Load or Form1_Paint event? I'd like to play with it.
Private Sub Form1_Paint(ByVal sender As Object, ByVal e _
As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim bPen As New Drawing.Pen(Color.Chocolate, 1)
e.Graphics.DrawLine(bPen, 0, 100, Me.Width, 100)
bPen.Dispose()
End Sub

Gene
 
Hi Cj,

I think using GDI+ to draw a line on the form is a better choice. A control
like label on the form requires a lot of extra code such as maintaining a
message loop, control painting code, maintaining window class structure,
interacting with OS Windows Manager component etc.. which more expensive
than a single GDI+ line drawing calling.

Additionally, Label can only express a vertical or horizontal line on the
form and can not meet your bias drawing need. However this can be easily
achieved by using GDI+.

Using GDI+ is much easier than you think(actually .Net Winform controls
internally use GDI+ to draw its appearance). "gene kelley" has provided you
a little sample code snippet, you may give it a try.

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Jeffrey,

Creating a dataclass is as well relative easy, it takes some time, therefore
I am glad that Microsoft did it already for us by all those things that are
in the system.data namespace. (And have created that great new part in 2.0
around that).

Of course you can do everything by a GDI class, but that creating a line in
HTML is one of the main tags <HR> means that it is one of the main things.
Your statement sound for me that it is no problem to eat with your feets. I
prefer using my hands for that.

Just my thought,

Cor
 
Jeffrey,

I have even a more important argument.

How can I put a line on a screen while being in Designer mode.

Cor
 
cj,
In addition to the other comments:

The following articles discusses how to create a .NET Line control that
wraps Win32 STATIC controls. useful for lines in dialog boxes (not grids per
se).
http://www.codeproject.com/cs/miscctrl/hvrules1.asp


--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Back in VB4 there was a line tool in my toolbox that allowed me to put a
| decorative line on the form somewhere. Does VB.net 2003 offer this?
| It's not in the toolbox and I can't find it in the list to add to the
| toolbox.
 
Thanks for this code. I was just dealing with the same issue recently,
and also could not believe vb.net doesn't have the "line" tool anymore.
 
Back
Top