Home All Groups Group Topic Archive Search About
Author
28 Jun 2005 7:22 PM
Mike L
In VB.NET Windows Form, how do I add a line across the form?

Author
28 Jun 2005 7:35 PM
Chris
Mike L wrote:
> 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
Author
28 Jun 2005 8:55 PM
Herfried K. Wagner [MVP]
Show quote Hide quote
"Chris" <no@spam.com> schrieb:
>> 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)

'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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
29 Jun 2005 3:11 PM
Chris
Herfried K. Wagner [MVP] wrote:
Show quoteHide quote
> "Chris" <no@spam.com> schrieb:
>
>>> 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)
>
>
> '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
Author
29 Jun 2005 3:43 PM
Herfried K. Wagner [MVP]
Show quote Hide quote
"Chris" <no@spam.com> schrieb:
>>> 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.
>>
>
> 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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
28 Jun 2005 7:40 PM
Armin Zingler
"Mike L" <Cadel@nospam.nospam> schrieb
> In VB.NET Windows Form, how do I add a line across the form?



http://msdn.microsoft.com/library/en-us/cpguide/html/_gdiplus_drawing_a_line_usecsharp.asp

(same via <F1>)

Armin
Author
29 Jun 2005 12:56 AM
Ken Tucker [MVP]
Hi,

        A line and shape control I created.

www.windowsformsdatagridhelp.info/downloads/shapedemo.zip

Ken
-----------------
"Mike L" <Cadel@nospam.nospam> wrote in message
news:2B5A7051-B557-4FA3-928E-BB6907A00F4D@microsoft.com...
In VB.NET Windows Form, how do I add a line across the form?
Author
29 Jun 2005 8:39 AM
Herfried K. Wagner [MVP]
"Mike L" <Cadel@nospam.nospam> schrieb:
> 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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
30 Jun 2005 9:00 PM
Mike L
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.

Show quoteHide quote
"Herfried K. Wagner [MVP]" wrote:

> "Mike L" <Cadel@nospam.nospam> schrieb:
> > 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.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
>