Draw a horizontal line on the form without using GDI

A

A.M-SG

Hi,



How do I draw a vertical or horizontal line on a form without using GDI?



Thank you,

Alan
 
H

Herfried K. Wagner [MVP]

A.M-SG said:
How do I draw a vertical or horizontal line on a form without using GDI?

Override the form's 'OnPaint' method and use 'e.Graphics.DrawLine' to draw
the line.
 
A

A.M-SG

I don’t think using GDI is not appropriate for this.



At this point I use an empty PictureBox with border and make the width or
height “1” to have vertical or horizontal lines. I am wondering is this the
best way to do it or not.
 
J

Jeffrey Tan[MSFT]

Hi,

Thanks for your feedback.

I am not sure what is your real concern. Why you can not use GDI to draw
the line?

Yes, I think your workaround of using picturebox border should work.
However, because control embeded extra code in it, which may cost some
performance. So I think using GDI to draw the line should be more
effective. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
S

Stoitcho Goutsev \(100\)

A.M-SG,

Without using GDI? I suppose you are after a control that you can drop on
the form.
In this case you can use a Panel which width or height property is set to
something small - say 4. Playing withe the border style you can gat pretty
decent results.
The other option would be the splitter control if you need resizable
divider.
 
H

Herfried K. Wagner [MVP]

A.M-SG said:
I don’t think using GDI is not appropriate for this.

At this point I use an empty PictureBox with border and make the width or
height “1” to have vertical or horizontal lines. I am wondering is this
the best way to do it or not.

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

Guest

Alan,

A very simple solution is to use a Label control. Give the Text property an
empty string and just make the size either tall and thin or wide and narrow.
Changing the border style to FixedSingle may also be appropriate.

Hope this helps.
Dave
 

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

Top