Difference between revisions of "TToggleBox/fr"

From Lazarus wiki
Jump to navigationJump to search
(Created page with "{{TToggleBox}} Un '''TToggleBox''' image:ttogglebox.png est bouton étiqueté à deux états qui est activé ou désactivé avec un simple clic. Partout dans votre code...")
 
m
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{TToggleBox}}
 
{{TToggleBox}}
  
Un '''TToggleBox''' [[image:ttogglebox.png]] est bouton étiqueté à deux états qui est activé ou désactivé avec un simple clic.
+
Un '''TToggleBox''' [[image:ttogglebox.png]] 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 '''<code>Status := <ToggleBox>.Checked;</code>'''. Vous pouvez aussi utiliser Checked comme un [[Boolean/fr|booléen]] normal. Il en est ainsi même en affection '''<code><ToggleBox>.Checked := True;</code>'''.
 
Partout dans votre code source, vous pouvez contrôler l'état actif ou inactif, en interrogeant '''<code>Status := <ToggleBox>.Checked;</code>'''. Vous pouvez aussi utiliser Checked comme un [[Boolean/fr|booléen]] normal. Il en est ainsi même en affection '''<code><ToggleBox>.Checked := True;</code>'''.
Line 11: Line 11:
 
* Créez le gestionnaire d'événement ''OnClick'' du TButton, allez sur l'onglet Evénements de l'inspecteur d'objet, sélectionnez l'événement ''OnClick'' et le bouton [...] ou faites un simple double-clic sur le bouton.
 
* Créez le gestionnaire d'événement ''OnClick'' du TButton, allez sur l'onglet Evénements de l'inspecteur d'objet, sélectionnez l'événement ''OnClick'' et le bouton [...] ou faites un simple double-clic sur le bouton.
 
* Ajoutez le code suivant dans le gestionnaire d'événement de ''btnPaint'' :
 
* Ajoutez le code suivant dans le gestionnaire d'événement de ''btnPaint'' :
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
procedure TForm1.btnPaintClick(Sender: TObject);
 
procedure TForm1.btnPaintClick(Sender: TObject);
 
var
 
var
Line 28: Line 28:
  
 
= Utiliser un événement =
 
= Utiliser un événement =
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.
+
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.
  
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:
+
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 :
* Create a new application and drop three TToggleBoxes on the form.
+
* Créez une nouvelle application et placez trois TToggleBoxes sur la fiche.  
* Change the captions of ToggleBox1...3 to ''Red'', ''Green'' and ''Blue'' and it names to ''tbRed'', ''tbGreen'' und ''tbBlue''.
+
* Modifiez les propriétés Caption des ToggleBox1...3 en ''Red'', ''Green'' et ''Blue'' et nommez-les ''tbRed'', ''tbGreen'' et ''tbBlue''.
* Create a ''OnChange'' event handler for one of the ToggleBoxes, e.g. '''<code>TForm1.tbRedChange(Sender: TObject);</code>''' and also connect the other ToggleBoxes with it:
+
* Créez un gestionnaire d'événement ''OnChange'' pour l'un des TToggleBox p.ex. '''<code>TForm1.tbRedChange(Sender: TObject);</code>''' et associez-le aux événements ''OnChange'' des autres TToggleBox :
** Doubleclick ''tbRed'' on your form or select ''tbRed'' on your form and go in the Object Inspector on the tab events, select the ''OnChange'' event and click on the button [...].
+
** Double-cliquez ''tbRed'' sur votre fiche ou sélectionnez ''tbRed'' sur votre fiche, allez sur l'onglet de l'inspecteur d'objet, sélectionnez l'événement ''OnChange'' et cliquez sur le bouton [...].
** It creates the procedure ''tbRedChange''.
+
** Cela crée la méthode ''tbRedChange''.
** Now select ''tbGreen'' on your form.
+
** Maintenant sélectionnez ''tbGreen'' sur votre fiche.
** Go in the Object Inspector to the tab events, choose the ''OnChange'' event and select ''tbRedChange'' in the adjacent combobox.
+
** Allez dans l'onglet Evénements de l'inspecteur d'objet, choisissez l'événement ''OnChange'' et sélectionnez ''tbRedChange'' dans le ComboBox adjacent.
** Now on your form, select ''tbBlue'' and proceed as with ''tbGreen''.
+
* Maintenant sur votre fiche, sélectionnez ''tbBlue'' et procédez de la même façon qu'avec ''tbGreen''.
* Get the event handler ''OnChange'' of the ToggleBoxes the colors of the form, according to ''<ToggleBox>.Checked'', change:
+
* Dans le gestionnaire d'événement ''tbRedChange'', la couleur de la fiche est modifiée selon l'état des boutons :
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
procedure TForm1.tbRedChange(Sender: TObject);  
 
procedure TForm1.tbRedChange(Sender: TObject);  
 
var
 
var

Latest revision as of 08:19, 13 December 2020

Deutsch (de) English (en) suomi (fi) français (fr) 日本語 (ja) русский (ru)

Un TToggleBox ttogglebox.png 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

  • Créez une nouvelle application et placez trois TToggleBoxes sur la fiche.
  • Modifiez les propriétés Caption des ToggleBox1...3 en Red, Green et Blue et nommez-les tbRed, tbGreen et tbBlue.
  • Ajoutez à la fiche un TButton et changez son intitulé en Paint new et son nom en btnPaint.
  • Créez le gestionnaire d'événement OnClick du TButton, allez sur l'onglet Evénements de l'inspecteur d'objet, sélectionnez l'événement OnClick et le bouton [...] ou faites un simple double-clic sur le bouton.
  • Ajoutez le code suivant dans le gestionnaire d'événement de btnPaint :
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;
  • Démarrez votre programmen il devrait ressembler à ceci :

ToggleBoxExample1.png -> ToggleBoxExample2.png

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 :

  • Créez une nouvelle application et placez trois TToggleBoxes sur la fiche.
  • Modifiez les propriétés Caption des ToggleBox1...3 en Red, Green et Blue et nommez-les tbRed, tbGreen et tbBlue.
  • Créez un gestionnaire d'événement OnChange pour l'un des TToggleBox p.ex. TForm1.tbRedChange(Sender: TObject); et associez-le aux événements OnChange des autres TToggleBox :
    • Double-cliquez tbRed sur votre fiche ou sélectionnez tbRed sur votre fiche, allez sur l'onglet de l'inspecteur d'objet, sélectionnez l'événement OnChange et cliquez sur le bouton [...].
    • Cela crée la méthode tbRedChange.
    • Maintenant sélectionnez tbGreen sur votre fiche.
    • Allez dans l'onglet Evénements de l'inspecteur d'objet, choisissez l'événement OnChange et sélectionnez tbRedChange dans le ComboBox adjacent.
  • Maintenant sur votre fiche, sélectionnez tbBlue et procédez de la même façon qu'avec tbGreen.
  • Dans le gestionnaire d'événement tbRedChange, la couleur de la fiche est modifiée selon l'état des boutons :
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


Composant LCL
Onglet de palette Composants
Standard TMainMenu • TPopupMenu • TButton • TLabel • TEdit • TMemo • TToggleBox • TCheckBox • TRadioButton • TListBox • TComboBox • TScrollBar • TGroupBox • TRadioGroup • TCheckGroup • TPanel • TFrame • TActionList
Additional TBitBtn • TSpeedButton • TStaticText • TImage • TShape • TBevel • TPaintBox • TNotebook • TLabeledEdit • TSplitter • TTrayIcon • TControlBar • TFlowPanel • TMaskEdit • TCheckListBox • TScrollBox • TApplicationProperties • TStringGrid • TDrawGrid • TPairSplitter • TColorBox • TColorListBox • TValueListEditor
Common Controls TTrackBar • TProgressBar • TTreeView • TListView • TStatusBar • TToolBar • TCoolBar • TUpDown • TPageControl • TTabControl • THeaderControl • TImageList • TPopupNotifier • TDateTimePicker
Dialogs TOpenDialog • TSaveDialog • TSelectDirectoryDialog • TColorDialog • TFontDialog • TFindDialog • TReplaceDialog • TOpenPictureDialog • TSavePictureDialog • TCalendarDialog • TCalculatorDialog • TPrinterSetupDialog • TPrintDialog • TPageSetupDialog • TTaskDialog
Data Controls TDBNavigator • TDBText • TDBEdit • TDBMemo • TDBImage • TDBListBox • TDBLookupListBox • TDBComboBox • TDBLookupComboBox • TDBCheckBox • TDBRadioGroup • TDBCalendar • TDBGroupBox • TDBGrid • TDBDateTimePicker
Data Access TDataSource • TBufDataset • TMemDataset • TSdfDataSet • TFixedFormatDataSet • TDbf
System TTimer • TIdleTimer • TLazComponentQueue • THTMLHelpDatabase • THTMLBrowserHelpViewer • TAsyncProcess • TProcessUTF8 • TProcess • TSimpleIPCClient • TSimpleIPCServer • TXMLConfig • TEventLog • TServiceManager • TCHMHelpDatabase • TLHelpConnector
Misc TColorButton • TSpinEdit • TFloatSpinEdit • TArrow • TCalendar • TEditButton • TFileNameEdit • TDirectoryEdit • TDateEdit • TTimeEdit • TCalcEdit • TFileListBox • TFilterComboBox • TComboBoxEx • TCheckComboBox • TButtonPanel • TShellTreeView • TShellListView • TXMLPropStorage • TINIPropStorage • TIDEDialogLayoutStorage • TMRUManager • TStrHolder
LazControls TCheckBoxThemed • TDividerBevel • TExtendedNotebook • TListFilterEdit • TListViewFilterEdit • TTreeFilterEdit • TShortPathEdit • TLvlGraphControl
RTTI TTIEdit • TTIComboBox • TTIButton • TTICheckBox • TTILabel • TTIGroupBox • TTIRadioGroup • TTICheckGroup • TTICheckListBox • TTIListBox • TTIMemo • TTICalendar • TTIImage • TTIFloatSpinEdit • TTISpinEdit • TTITrackBar • TTIProgressBar • TTIMaskEdit • TTIColorButton • TMultiPropertyLink • TTIPropertyGrid • TTIGrid
SQLdb TSQLQuery • TSQLTransaction • TSQLScript • TSQLConnector • TMSSQLConnection • TSybaseConnection • TPQConnection • TPQTEventMonitor • TOracleConnection • TODBCConnection • TMySQL40Connection • TMySQL41Connection • TMySQL50Connection • TMySQL51Connection • TMySQL55Connection • TMySQL56Connection • TSQLite3Connection • TIBConnection • TFBAdmin • TFBEventMonitor • TSQLDBLibraryLoader
Pascal Script TPSScript • TPSScriptDebugger • TPSDllPlugin • TPSImport_Classes • TPSImport_DateUtils • TPSImport_ComObj • TPSImport_DB • TPSImport_Forms • TPSImport_Controls • TPSImport_StdCtrls • TPSCustomPlugin
SynEdit TSynEdit • TSynCompletion • TSynAutoComplete • TSynMacroRecorder • TSynExporterHTML • TSynPluginSyncroEdit • TSynPasSyn • TSynFreePascalSyn • TSynCppSyn • TSynJavaSyn • TSynPerlSyn • TSynHTMLSyn • TSynXMLSyn • TSynLFMSyn • TSynDiffSyn • TSynUNIXShellScriptSyn • TSynCssSyn • TSynPHPSyn • TSynTeXSyn • TSynSQLSyn • TSynPythonSyn • TSynVBSyn • TSynAnySyn • TSynMultiSyn • TSynBatSyn • TSynIniSyn • TSynPoSyn
Chart TChart • TListChartSource • TRandomChartSource • TUserDefinedChartSource • TCalculatedChartSource • TDbChartSource • TChartToolset • TChartAxisTransformations • TChartStyles • TChartLegendPanel • TChartNavScrollBar • TChartNavPanel • TIntervalChartSource • TDateTimeIntervalChartSource • TChartListBox • TChartExtentLink • TChartImageList
IPro TIpFileDataProvider • TIpHttpDataProvider • TIpHtmlPanel