Difference between revisions of "TRadioButton/fr"

From Lazarus wiki
Jump to navigationJump to search
(Created page with "{{TRadioButton}} Un '''TRadioButton''' image:tradiobutton.png est un composant qui affiche un bouton de sélection qui fonctionne avec d'autres RadioButtons d'une manièr...")
 
Line 3: Line 3:
 
Un '''TRadioButton''' [[image:tradiobutton.png]] est un composant qui affiche un bouton de sélection qui fonctionne avec d'autres RadioButtons d'une manière mutuellement exclusive - Si un button est sélectionné, aucun des autres dans le groupe ne peut être sélectionné. Le composant TRadioButton se trouve dans l'[[Standard tab/fr|onglet Standard]] de la [[Component Palette/fr|palette de composants]].
 
Un '''TRadioButton''' [[image:tradiobutton.png]] est un composant qui affiche un bouton de sélection qui fonctionne avec d'autres RadioButtons d'une manière mutuellement exclusive - Si un button est sélectionné, aucun des autres dans le groupe ne peut être sélectionné. Le composant TRadioButton se trouve dans l'[[Standard tab/fr|onglet Standard]] de la [[Component Palette/fr|palette de composants]].
  
* * * A FINIR  * * *
+
Pour utiliser un RadioButton sur une [[TForm/fr|fiche]], vous pouvez simplement le sélectionner sur la palette de composants ''Standard'' et le placer, avec un clic sur la fiche.<br/>
 +
Il ne sert à rien en général de poser un seul RadioButton, car les RadioButtons sont prévus pour choisir entre plusieurs alternatives. Ainsi, vous pouvez utiliser aussi un
 +
[[TRadioGroup/fr|TRadioGroup]] à la place de RadioButtons individuels.
  
To use a TRadioButton on a [[TForm|Form]], you can simply select it on the component palette ''Standard'' and place it, with one click on the form.<br>
+
Partout dans votre code source, vous pouvez obtenir l'état des RadioButtons, actif ou inactif, en interrogeant '''<code>Status := <RadioButton>.Checked;</code>'''. Vous pouvez utiliser ''Checked'' comme un [[Boolean/fr|booléen]] normal. Ainsi, l'affectation '''<code><RadioButton>.Checked := True;</code>''' est possible.
It usually does not make sense to use a single radiobutton, because radiobuttons are intended to select anything. Thus, you can instead of individual radiobuttons also a [[TRadioGroup]] use.
 
 
 
Anywhere in your source code, you can get the status of the radiobuttons, whether active or inactive, by query '''<code>Status := <RadioButton>.Checked;</code>'''. You can use ''Checked'' as a normal [[Boolean]]. Thus, the allocation '''<code><RadioButton>.Checked := True;</code>''' is possible.
 
  
 
= Un simple exemple =
 
= Un simple exemple =
* Create a new application and drop three TRadioButtons on the form.
+
* Créez une nouvelle application et placez trois RadioButtons sur la fiche.
* In the Object Inspector tab properties change the name the ''RadioButton1...3'' to ''rbRed'', ''rbGreen'' and ''rbBlue''.
+
* Dans l'onglet Propriétés de l'inspecteur d'objets, changez les noms des RadioButtons en ''rbRed'', ''rbGreen'' et ''rbBlue''.
* Similarly, you change the captions of the radiobuttons to ''Red'', ''Green'' and ''Blue'' there.
+
* De la même façon, vous pouvez changer les intitulés des RadioButtons en ''Red'', ''Green'' et ''Blue''.
* Add your form a [[TButton]] and change its caption to ''Draw new'' and its name to ''btnPaint''.
+
* Ajoutez à votre fiche, un bouton et changez son intitulé en ''Draw new'' et son nom en ''btnPaint''.
* Create the ''OnClick'' event handler for the TButton, by using the Object Inspector tab events, select the ''OnClick'' event and click the button [...] or double click the button in the form.
+
* Créez le gestionnaire d'événement ''OnClick'' pour le bouton, en utilisant l'onglet Evénements de l'inspecteur d'objet, sélectionnez l'événement  OnClick et cliquez sur le bouton [...] ou double-cliquez le bouton sur la fiche.
* Add following code:
+
* Ajoutez le code suivant :
 
<syntaxhighlight>
 
<syntaxhighlight>
 
procedure TForm1.btnPaintClick(Sender: TObject);
 
procedure TForm1.btnPaintClick(Sender: TObject);
Line 25: Line 24:
 
end;
 
end;
 
</syntaxhighlight>
 
</syntaxhighlight>
* Open your application, it should look something like:
+
* Ouvrez votre application, elle devrait ressembler à quelque chose comme cela :
  
 
[[image:RadioButtonExample1.png]] -> [[image:RadioButtonExample2.png]]
 
[[image:RadioButtonExample1.png]] -> [[image:RadioButtonExample2.png]]
  
 
= Usage d'un événement =
 
= Usage d'un événement =
The difference to the previous example is, we repaint the form not by a button click, but already by clicking one of the radio buttons themselves.<br>
+
A la différence avec l'exemple précédent, nous ne repeignons pas la fiche en cliquant sur le bouton mais en cliquant sur les RadioButtons eux-mêmes.<br/>
  
You can modify the previous example, by deleting the button and its ''OnClick'' event handler in the source code. You can create a new example but also easy:
+
Vous pouvez modifier l'exemple précédent, en supprimant le bouton et son gestionnaire d'événement ''OnClick'' dans le code source, vous pouvez créer un nouvel exemple mais aussi simple :
* Create a new application and drop three TRadioButtons on the form.
+
* Créez une nouvelle application et placez trois RadioButtons sur la fiche.
* In the Object Inspector tab properties change the name the ''RadioButton1...3'' to ''rbRed'', ''rbGreen'' and ''rbBlue''.
+
* Dans l'onglet Propriétés de l'inspecteur d'objets, changez les noms des RadioButtons en ''rbRed'', ''rbGreen'' et ''rbBlue''.
* Similarly, you change the captions of the radiobuttons to ''Red'', ''Green'' and ''Blue'' there.
+
* De la même façon, vous pouvez changer les intitulés des RadioButtons en ''Red'', ''Green'' et''Blue''.
* Now you can create the ''OnChange'' event handlers for the radiobuttons. For every radiobutton, you can use the Object Inspector tab events, select the ''Onchange'' event and click the button [...], but you can also doubleclick on it.
+
* Maintenant vous pouvez créer les gestionnaires d'événement pour les RadioButtons. Pour chacun d'eux, vous pouvez utiliser l'onglet événements de l'inspecteur d'objet, sélectionner l'événement ''OnChange'' et cliquez sur le bouton [...], vous pouvez aussi double-cliquer dessus.
* Let the event handler ''OnChange'' of the radio buttons change the colors of the form, according to clicked radio button:
+
* Faites changer la couleur de la fiche par le gestionnaire d'événement ''OnChange'' selon le RadioButton sélectionné :
 
<syntaxhighlight>
 
<syntaxhighlight>
 
procedure TForm1.rbRedChange(Sender: TObject);
 
procedure TForm1.rbRedChange(Sender: TObject);
Line 55: Line 54:
 
end;  
 
end;  
 
</syntaxhighlight>
 
</syntaxhighlight>
* Open your application, it should look something like:
+
* Ouvrez votre application, elle devrait ressembler à ceci :
  
 
[[image:RadioButtonExample3.png]] -> [[image:RadioButtonExample4.png]]
 
[[image:RadioButtonExample3.png]] -> [[image:RadioButtonExample4.png]]

Revision as of 07:40, 29 August 2017

Deutsch (de) English (en) suomi (fi) français (fr) 日本語 (ja)

Un TRadioButton tradiobutton.png est un composant qui affiche un bouton de sélection qui fonctionne avec d'autres RadioButtons d'une manière mutuellement exclusive - Si un button est sélectionné, aucun des autres dans le groupe ne peut être sélectionné. Le composant TRadioButton se trouve dans l'onglet Standard de la palette de composants.

Pour utiliser un RadioButton sur une fiche, vous pouvez simplement le sélectionner sur la palette de composants Standard et le placer, avec un clic sur la fiche.
Il ne sert à rien en général de poser un seul RadioButton, car les RadioButtons sont prévus pour choisir entre plusieurs alternatives. Ainsi, vous pouvez utiliser aussi un TRadioGroup à la place de RadioButtons individuels.

Partout dans votre code source, vous pouvez obtenir l'état des RadioButtons, actif ou inactif, en interrogeant Status := <RadioButton>.Checked;. Vous pouvez utiliser Checked comme un booléen normal. Ainsi, l'affectation <RadioButton>.Checked := True; est possible.

Un simple exemple

  • Créez une nouvelle application et placez trois RadioButtons sur la fiche.
  • Dans l'onglet Propriétés de l'inspecteur d'objets, changez les noms des RadioButtons en rbRed, rbGreen et rbBlue.
  • De la même façon, vous pouvez changer les intitulés des RadioButtons en Red, Green et Blue.
  • Ajoutez à votre fiche, un bouton et changez son intitulé en Draw new et son nom en btnPaint.
  • Créez le gestionnaire d'événement OnClick pour le bouton, en utilisant l'onglet Evénements de l'inspecteur d'objet, sélectionnez l'événement OnClick et cliquez sur le bouton [...] ou double-cliquez le bouton sur la fiche.
  • Ajoutez le code suivant :
procedure TForm1.btnPaintClick(Sender: TObject);
begin
  if rbRed.Checked   then Color:=clRed;
  if rbGreen.Checked then Color:=clLime;
  if rbBlue.Checked  then Color:=clBlue;
end;
  • Ouvrez votre application, elle devrait ressembler à quelque chose comme cela :

RadioButtonExample1.png -> RadioButtonExample2.png

Usage d'un événement

A la différence avec l'exemple précédent, nous ne repeignons pas la fiche en cliquant sur le bouton mais en cliquant sur les RadioButtons eux-mêmes.

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

  • Créez une nouvelle application et placez trois RadioButtons sur la fiche.
  • Dans l'onglet Propriétés de l'inspecteur d'objets, changez les noms des RadioButtons en rbRed, rbGreen et rbBlue.
  • De la même façon, vous pouvez changer les intitulés des RadioButtons en Red, Green etBlue.
  • Maintenant vous pouvez créer les gestionnaires d'événement pour les RadioButtons. Pour chacun d'eux, vous pouvez utiliser l'onglet événements de l'inspecteur d'objet, sélectionner l'événement OnChange et cliquez sur le bouton [...], vous pouvez aussi double-cliquer dessus.
  • Faites changer la couleur de la fiche par le gestionnaire d'événement OnChange selon le RadioButton sélectionné :
procedure TForm1.rbRedChange(Sender: TObject);
begin
  Self.Color:=clRed;    //with "Self", you select the object in which the method exists (method: rbRedChange / object: Form1)
end;

procedure TForm1.rbGreenChange(Sender: TObject);
begin
  Form1.Color:=clLime;  //You can directly select the object ''Form1'', but poor, 
                        //because then no other object of class 'TForm1' can be created
end;

procedure TForm1.rbBlueChange(Sender: TObject);
begin
  Color:=clBlue;        //or you leave out "Self" and the compiler will automatically detect its own object
end;
  • Ouvrez votre application, elle devrait ressembler à ceci :

RadioButtonExample3.png -> RadioButtonExample4.png

Groupement

If you add a radiobutton to your form is its parent (control, which includes the radio button) your form. By each setting (no matter whether via code or user button click) of a <RadioButton>.Checked:=True; is checked whether a different radiobutton, with this parent, is selected and if yes, the property Checked of this would be changed to False.
If you want to use multiple radiobuttons on your form, that are designed to provide different, independent choices, you must group the radio buttons. There are a finished component TRadioGroup or you group on a control (e.g. TPanel, TGroupBox, TNotebook, TPageControl etc.).

The following example shows how you can group radio buttons:

You can change the example A simple example or create a new application:

  • As first you would need to place a TGroupBox of the standard component palette onto your form.
  • You change its name to gbColor and its caption to Color.
  • Now you subclass this GroupBox that radio buttons rbRed, rbGreen and rbBlue:
    • In the modified project, you can sequentially move the radiobuttons in the Object Inspector by drag and drop to gbColor.
    • In a new project, you can insert the three radiobuttons one after the other, by clicking to insert in the GroupBox, then change the names to rbRed, rbGreen and rbBlue and the captions to Red, Green and Blue.
  • Now place a second TGroupBox on your form named gbBrightness with the caption Brightness.
  • Add this GroupBox also three radio buttons and give it the name rbBrightDark, rbBrightMedDark and rbBrightBright and the captions Dark, MediumDark and Bright.
  • If you have created a new application, you must add a button with name btnPaint and caption Draw new to the form.
  • In the OnClick event handler of btnPaint change the code to:
procedure TForm1.btnPaintClick(Sender: TObject);
begin
  if rbRed.Checked   then Color:=Brightness or clRed;
  if rbGreen.Checked then Color:=Brightness or clLime;
  if rbBlue.Checked  then Color:=Brightness or clBlue;  
end;
  • Now create even the function Brightness, by enter the private section of TForm1, write function Brightness: TColor; and press the keys [CTRL] + [Shift] + [c] (code completion). The function is created. Enter there following code:
function TForm1.Brightness: TColor;
begin
  Result:=0;
  if rbBrightMedDark.Checked then Result:=$888888;
  if rbBrightBright.Checked  then Result:=$DDDDDD;
end;
  • Start your application, you can use the grouped radio buttons separate, so it could look like:

RadioButtonExample5.png -> RadioButtonExample6.png

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