Sign in Join
Wiki copytemporary

TToggleBox/fr

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

Un TToggleBox est un bouton étiqueté à deux états qui est activé ou désactivé avec un simple clic.

Partout dans votre code source, vous pouvez contrôler l'état actif ou inactif, en interrogeant Status := <ToggleBox>.Checked;. Vous pouvez aussi utiliser Checked comme un booléen normal. Il en est ainsi même en affection <ToggleBox>.Checked := True;.

Un simple exemple

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;

->

Utiliser un événement

La différence avec l'exemple précédent est que la fiche ne sera pas repainte avec un clic sur un bouton mais directement en cliquant sur l'un des TToggleBox lui-même.

Vous pouvez modifier l'exemple précédent en supprimant le bouton et son gestionnaire d'événement OnClick dans le code source. Mais tout aussi simple vous pouvez créer un nouvel exemple :

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;

Voir aussi


From the Free Pascal wiki, page "TToggleBox/fr", as it stood on 2020-12-13 after a change by Beuz, 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.