Sign in Join
Wiki copytemporary

TToggleBox

Deutsch · English · Français · Suomi · Русский · 日本語

A TToggleBox is a two state labeled button that is enabled or disabled with a single click. It is available on the Standard tab of the Component Palette.

Anywhere in your source code, you can check the status, whether active or inactive, by query Status := <ToggleBox>.Checked;. You can use Checked as a normal Boolean. Thus, even an assignment, <ToggleBox>.Checked := True;, is possible.

A simple example

pascal
procedure TForm1.btnPaintClick(Sender: TObject);
var
  aColor: TColor;
begin
  aColor:=0;        //Background color of Form1 is set according to the Toggleboxes
  if tbRed.Checked   then aColor:=aColor + $0000FF;
  if tbGreen.Checked then aColor:=aColor + $00FF00;
  if tbBlue.Checked  then aColor:=aColor + $FF0000;
  Color := aColor;  //the change of the property <Formular>.Color causes a redrawing of the form
end;

->

Use an event

The difference to the previous example is, the form would not be repainted by a button click, but already by clicking on one of the toggleboxes itself.

You can modify the previous example, by deleting the button and its OnClick event handler in the source code. But also easy, you can create a new example:

pascal
procedure TForm1.tbRedChange(Sender: TObject); 
var
  aColor: TColor; 
begin
  aColor:=0;        //Background color of Form1 is set according to the Toggleboxes
  if ToggleBox1.Checked then aColor:=aColor + $0000FF;
  if ToggleBox2.Checked then aColor:=aColor + $00FF00;
  if ToggleBox3.Checked then aColor:=aColor + $FF0000;
  Color := aColor;  //the change of the property <Formular>.Color causes a redrawing of the form
end;

See also


From the Free Pascal wiki, page "TToggleBox", as it stood on 2019-11-09 after a change by Djzepi, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.