TLabel with border. lazarus / 31-LCL ---------------------------------------------------------------------- dicas3d · 2011-06-07 12:13 Hi. Hi research lots of times in google how to put borders on a Label. I need to know how to do it. How I put borders on a Label? ---------------------------------------------------------------------- Blaazen · 2011-06-07 12:28 I don't know if it is possible with TLabel. But you can use TPanel. It has Caption and Borders. See screenshot. ---------------------------------------------------------------------- Arbee · 2011-06-07 12:41 Or use a TLabel within a TShape. ---------------------------------------------------------------------- typo · 2011-06-07 13:44 Code: [Select]Label1.Canvas.Rectangle(0,0,Label1.Width, Label1.Height); You could put it on an OnPaint event of the form. ---------------------------------------------------------------------- Blaazen · 2011-06-07 14:27 @typo Strange, it works bad on Qt widgetset. I have to use: Code: [Select]  with Label2 do     Canvas.Rectangle(Left, Top, Left+Width, Top+Height); to set correct position. And when I close form it gives SIGSEGV in function Code: [Select]function TQtWidgetSet.IsValidGDIObject(const GDIObject: HGDIOBJ): Boolean;Maybe I will do bugreport. There are also Canvas.Frame3D functions. ---------------------------------------------------------------------- typo · 2011-06-07 14:45 QuoteMaybe I will do bugreport. Yes. ---------------------------------------------------------------------- dicas3d · 2011-06-07 14:53 And I when I try create the event OnPaint by design he says Unable to create the new method. Please fix the error shown in the message window, whick is normally bellow the source editor. The bug is in the unit Controls and is Error: [TFindDeclarationTool.FindCodeToolForUsedUnit] internal error: invalid UnitNameAtom . Will I do bugreport? ---------------------------------------------------------------------- typo · 2011-06-07 15:02 I think it is not a bug, this means that the compiler has found an error in your code. Try to fix it. ---------------------------------------------------------------------- dicas3d · 2011-06-07 15:04 Until with an empty project it do error. ---------------------------------------------------------------------- Arbee · 2011-06-07 15:09 Don't think this is right anyway ... Code: [Select] with Label2 do     Canvas.Rectangle(Left, Top, Left+Width, Top+Height); You'ld be using the "left" and "top" position of the label on the form, not the canvas of the label, I assume. ---------------------------------------------------------------------- dicas3d · 2011-06-07 15:11 Canvas is a graphical class for Lazarus. Losts of components like forms have it. ---------------------------------------------------------------------- Arbee · 2011-06-07 15:16 I know, but if you use the "left" and "top" like that you won't see any rectangle around your label because the coordinates are all off: Code: [Select]  with Label2 do     Canvas.Rectangle(Left, Top, Left+Width, Top+Height); does not show a rectangle, but this one does (at least on my XP machine) Code: [Select]  with Label2 do     Canvas.Rectangle(0, 0, Width, Height); ---------------------------------------------------------------------- dicas3d · 2011-06-07 15:27 Width and heigth are the properties of Label that indicate the size of the Label. Left and Top indicate where the label is started draw. So by sum Left more width you obtain the coordinate x of the left corner. By sum top with heigth you obtain the coordinate y of the left corner of the Label. ---------------------------------------------------------------------- Arbee · 2011-06-07 15:31 Which is precisely why Code: [Select]with Label2 do     Canvas.Rectangle(Left, Top, Left+Width, Top+Height); does not work and why Code: [Select]with Label2 do     Canvas.Rectangle(0,0, Width, Height); does. See two screen shots: ---------------------------------------------------------------------- dicas3d · 2011-06-07 16:56 This can work on your case: Code: [Select]with Label1 do [code]Canvas.Rectangle(left,top, Width, Height);. But with me I can't see any Rectangle around My Label. Code: [Select]with Label1 do Canvas.Rectangle(0,0, Width, Height);[/code] ---------------------------------------------------------------------- dicas3d · 2011-06-07 17:11 Code: [Select]Label1.Canvas.Rectangle(0,0,Label1.Width, Label1.Height); No rectangle. ---------------------------------------------------------------------- User137 · 2011-06-07 17:30 Each component has its own canvas that starts from 0, 0. If you have a TPaintBox for example you draw to it starting from 0, 0. If you move its Left and Right elsewhere the graphics move along with it. However, if i start new project and create new label with default properties on form, and put this in FormPaint event Code: [Select]  with Label1 do begin     canvas.Pen.Color:=clBlack;     canvas.Pen.Width:=1;     canvas.Brush.Style:=bsClear;     Canvas.Rectangle(0, 0, Width, Height);   end;     I do not see a rectangle. I tried with setting its Transparent property false and Color property to clBtnFace, but still not seeing it. Lazarus 0.9.31 SVN 29541, fpc 2.4.3. Windows 7 32-bit. edit: if i add Label1.Repaint; after Rectangle it shows, and is flashing. But it seems like endless loop that hangs up application. I had to stop the app from Lazarus as it refused to close. ---------------------------------------------------------------------- garlar27 · 2011-06-07 18:11 Maybe I'm late here, and I haven't read all post but, you can use TStaticText. Or you have problems with it? ---------------------------------------------------------------------- eny · 2011-06-07 18:50 If you create your own label component you can do whatever you need/want. ---------------------------------------------------------------------- Blaazen · 2011-06-07 19:24 I reported bug: http://bugs.freepascal.org/view.php?id=19516 because it seems that Windows and Linux+Qt has different behaviour. ---------------------------------------------------------------------- User137 · 2011-06-07 19:49 What is Qt? I'm just using the default components and packages unless its same thing. ---------------------------------------------------------------------- dicas3d · 2011-06-08 11:50 You need put the line Repaint on the place that you need that the rectangle appear. Example:onClick ---------------------------------------------------------------------- dicas3d · 2011-06-08 12:07 I no work well. ---------------------------------------------------------------------- dicas3d · 2011-06-09 10:41 I solve the problem and put the solution on My blog at http://pprograming.blogspot.com/2011/06/text-with-borders-no- problem.html .