Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I draw a horizontal rule? 1

Status
Not open for further replies.

capitano

Programmer
Jul 30, 2001
88
US
I see a lot of forms with horizontal lines used as separators for aesthetic reasons. How does one draw a horizontal rule, or separator on a Windows form? I expect there would be a utility for this in the toolbox along with labels, buttons, check-boxes, picture boxes, etc. Seems like a common enough thing, but I just cannot figure it out where or how to do it. Does anybody know??

Help!

Thanks,
Bryan
 
Use GDI+ to do this. In your form's OnPaint event, do something like this:
Code:
  Dim pen As New Pen(Color.LightGray)
  e.Graphics.DrawLine(pen, 0, 100, me.Width, 100)
  pen.Color = Color.DarkGray
  e.Graphics.DrawLine(pen, 1, 101, me.Width - 1, 101)
This draws two lines, one light gray, and another dark gray line below, and offset to the right by one pixel to give a 3d effect.

Chip H.
 

there is another way:

Steps:
1. add a label
2. rip out the text
3. set the backgound color to black
4. set height to 1.

For vertical lines set the width to 1 insead of height.
 
Chip,

How do you make the pen draw on top of other objects (i.e. GroupBoxes, Buttons, TabControls)?

Thanks. --------------------------------------
Is George Lucas Kidding...
Noise Core: 7.62
 
If you do it my way then you use the "Bring to Front" and "Send to Back" buttons on the layout toolbar.
 
Try this:
Code:
Dim MyGraphics as Graphics
Dim MyPen as Pen

Set MyGraphics = MyButton.CreateGraphics()
Set MyPen = new Pen(Pens.Black)

MyGraphics.DrawLine(MyPen, 0, 0, 100, 100)

MyGraphics.Dispose()
Set MyPen = Nothing
Set MyGraphics = Nothing

Haven't tested it, but from the docs, it looks like it might work.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top