Forum > Beginners

Adding border to component

(1/2) > >>

Trenatos:
I've looked around but not found a solution, is there a way to add a border to a component programmatically, or will I have to look into drawing lines and shapes?

molly:
Which specific component are you talking about ?

TComponent is non visual, so would not be suited to draw a border.

It's common to inherit from something like tcustomcontrol, which brings you canvas etc. that you can draw to. That control has a borderstyle property (which can be set or not), or alternatively you can use a canvas to f.e. draw a 3D frame.

Edit: add small example

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;  type  TMyCustomControl = class(TCustomControl)  end; type   { TForm1 }   TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);  private    { private declarations }  public    { public declarations }    MyCustomControl : TMyCustomControl;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  MyCustomControl := TMyCustomControl.Create(Self);  MyCustomControl.Parent := Self;  MyCustomControl.Left := 100;  MyCustomControl.Top := 100;  MyCustomControl.Width := 100;  MyCustomControl.Height := 100;  MyCustomControl.BorderStyle:= bsSingle; // bsNone;end; end. 

Trenatos:
Hi Molly

I'm creating buttons, panels, and other things dynamically and am trying to add a border to show onclick to show the currently active item in an editor.

If I understand you right, I should be able to create a button and inherit from customcontrol, which has the ability to use a border or draw one?

molly:
Hi Trenatos,


--- Quote from: Trenatos on May 04, 2016, 05:00:53 pm ---If I understand you right, I should be able to create a button and inherit from customcontrol, which has the ability to use a border or draw one?

--- End quote ---
Nope. My answer was placed in another context, as your situation was not clear yet :-)

The 'normal' way to do that, and assuming you use standard LCL controls is to inherit _all_ your controls to be able to draw a custom border as you wish, or 'abuse' the design interface of the components (i do not have experience with the latter)


--- Quote ---I'm creating buttons, panels, and other things dynamically and am trying to add a border to show onclick to show the currently active item in an editor.

--- End quote ---
Still not sure if you are using standard LCL controls.

If this is for using standard LCL controls _and_ has to work for Windows only, then i might be able to come up with a generic workaround.

Trenatos:
I'm using standard controls for the moment but haven't decided what to use for long term, if images would work or more likely I'd have to make custom controls (Which I've never made before) to support scaling, borders, various shapes, etc.

It needs to work for both Windows and Mac.

I don't know if this information is of use for the answer, but maybe;
I'm working on a wysiwyg editor, I'm able to drag-and-drop items from a menu and create them dynamically in the editor area, they're clickable and sets an activeItem variable, but I need some kind of visual indicator of what the currently active item is, so if there's a better way to do it then I'm all ears.

Navigation

[0] Message Index

[#] Next page

Go to full version