Line across form

  • Thread starter Thread starter Guest
  • Start date Start date
Mike said:
In VB.NET Windows Form, how do I add a line across the form?

I did this inside of the forms paint method. Hope it helps.

Chris

Private Sub Main_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Dim Pen As New Pen(Color.MediumBlue, 2)
Dim TopLine As Integer = 150
Dim BottomLine As Integer = 388
e.Graphics.DrawLine(Pen, 0, TopLine, 640, TopLine)


End Sub
 
Chris said:
I did this inside of the forms paint method. Hope it helps.

Chris

Private Sub Main_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Dim Pen As New Pen(Color.MediumBlue, 2)
Dim TopLine As Integer = 150
Dim BottomLine As Integer = 388
e.Graphics.DrawLine(Pen, 0, TopLine, 640, TopLine)

'Pen' objects should be disposed if they are not needed any more. It's
better to store the 'Pen' object in a private variable, for example, instead
of creating a new pen every time the form is drawn.
 
Mike L said:
In VB.NET Windows Form, how do I add a line across the form?

Shapes and lines:

Advanced Shape Control
<URL:http://www.codeproject.com/vb/net/advanced_shape_control.asp>

LineControls.exe
<URL:http://www.gotdotnet.com/team/vb/LineControls.exe>
<URL:http://download.microsoft.com/download/7/e/0/7e070297-47fe-4443-9194-ab57acd8ea01/LineControls.msi>

Creating transparent Windows Forms controls.
<URL:http://www.bobpowell.net/transcontrols.htm>

Rules:

Wrapping Win32 Controls in .NET - Horizontal and Vertical Rules
<URL:http://www.codeproject.com/cs/miscctrl/hvrules1.asp>

Alternatively you can use a label control with width or height set to 2, and
'BorderStyle' set to 'Fixed3D' to create an inset line.
 
Herfried said:
'Pen' objects should be disposed if they are not needed any more. It's
better to store the 'Pen' object in a private variable, for example,
instead of creating a new pen every time the form is drawn.

Thanks for the info. If I use the same pen for the life of the form
should I still dispose of it when the form is closed, or will the
auto-disposing of the form take care of it for me?

chris
 
Chris said:
Thanks for the info. If I use the same pen for the life of the form
should I still dispose of it when the form is closed, or will the
auto-disposing of the form take care of it for me?

You may want to call the pen's 'Dispose' method in the form's overridden
'Dispose' method.
 
Your answer worked best, I used the simple label control, set it to black and
resized using the mouse. Did it in less than a second and I didn't have to
write one line of code. Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top