2

I often use a TPanel or TGroupBox to group my form controls.

Now I need to draw just a straight line like the border of a Panel or GroupBox.

How do I do this on LAZARUS?

Thanks in advance!

Note: The technique must work on both Linux and Windows

itsols
  • 5,406
  • 7
  • 51
  • 95
  • Can you be more specific or perhaps mock up what you want using a graphics editor? See here for possible ideas: http://stackoverflow.com/questions/813693/how-to-draw-on-a-tpanel. But it's unclear if this is what you should do without knowing the context. – lurker Aug 10 '13 at 14:16
  • Take for instance the TPanel. It draws a nice border on 4 sides. I just want a single side. In other words, I just want a line. The line must be on the form. For example, I can have two text boxes, one below the other, and the line as a separator. But this line must look like the border of a TPanel. I hope that is clear :) – itsols Aug 10 '13 at 15:53
  • As an optical line separator you should use either `TBevel` (with `Shape` set to `bs...Line` shape, where `...` stands for `Top`, `Left`, `Bottom` or `Right`), or `TDividerBevel` components. They're intender for this purpose and instead of direct painting on the form, you can select them with the other components and move them across the form at design time. But if you really want to show how to draw on the form, notify me through the comment and I'll post you a simple example. – TLama Aug 11 '13 at 12:21
  • @TLama I think your method is good as well. Please post it as an answer. – itsols Aug 11 '13 at 16:07

2 Answers2

1

As an optical line separator you should use either the TBevel component with Shape property set to one of the following values bsTopLine, bsBottomLine, bsLeftLine or bsRightLine depending on which line you currently need and resize it to a smaller size (in your case you can use bsTopLine or bsBottomLine and resize the bevel vertically):

enter image description here

Or you can use a special component called TDividerBevel which except the single line adds to this optical divider also a caption:

enter image description here

TLama
  • 75,147
  • 17
  • 214
  • 392
0

Here's what I've finally done but I'm not sure if this is the RIGHT way so I won't accept my answer. If there's someone else who can point out any issues with this, please let me know. I found this pretty straightforward as well :)

  1. Place a TGroupBox on the form.
  2. Leave the Caption property blank. Now it should look like a panel with only borders.
  3. Use the mouse and drag the bottom border towards the top. Now it looks like a line.

Well, I personally think this method is NOT efficient as it would take up more memory space than just a real straight line. Anyway, so far it seems to work for me :)

Here's the screenshot - look towards the bottom (just above the last text box). The only issues is that on the sides of the line, it shows the lines bending. I think I should set the properties correctly than dragging with the mouse.

enter image description here

itsols
  • 5,406
  • 7
  • 51
  • 95
  • I've seen also some people placing a `TPanel` and resizing it the same way as you did with a group box, but e.g. a group has a different look on Windows XP and Vista above when its caption is empty. The panel doesn't have this problem, but there's no need for this workaround while there is a component just for this purpose ;-) – TLama Aug 11 '13 at 17:06