1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
RadioGroup1: TRadioGroup;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure FormActivate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
Nb_BoutonRadio:integer;
procedure OnClickRadioButton(Sender: TObject);
end;
var
Form1: TForm1;
PositionTopRadioButton:integer;
RadioButtons: array of TControl;
implementation
{$R *.dfm}
procedure TForm1.FormActivate(Sender: TObject);
begin
Nb_BoutonRadio:=10;
Button1.Enabled:=True;
Button2.Enabled:=False;
Button3.Enabled:=False;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
RadioGroup1.Width:=150;
PositionTopRadioButton:=25;
for i:=0 to Nb_BoutonRadio do
begin
SetLength(RadioButtons,Length(RadioButtons)+1);
RadioButtons[i]:=TRadioButton.Create(Application);
(RadioButtons[i] as TRadioButton).Parent:=RadioGroup1;
(RadioButtons[i] as TRadioButton).Name:='RadioButton'+IntToStr(i);
(RadioButtons[i] as TRadioButton).Width:=110;
// Alterner bêtement la couleur de Font
if i mod 2 = 0 then
(RadioButtons[i] as TRadioButton).Font.Color:=clBlack
else
(RadioButtons[i] as TRadioButton).Font.Color:=clBlue;
// ***********************************
(RadioButtons[i] as TRadioButton).Caption:='Bouton-radio n°'+IntToStr(i);
(RadioButtons[i] as TRadioButton).Top:=PositionTopRadioButton;
(RadioButtons[i] as TRadioButton).Left:=20;
(RadioButtons[i] as TRadioButton).OnClick:=OnClickRadioButton;
PositionTopRadioButton:=PositionTopRadioButton+20;
end;
RadioGroup1.Height:=Length(RadioButtons)*21+30;
Button1.Enabled:=False;
Button2.Enabled:=True;
Button3.Enabled:=True;
end;
// Alterner bêtement la couleur de Font
procedure TForm1.Button2Click(Sender: TObject);
var i:integer;
Premier:string;
begin
Premier:='Rouge';
if (RadioButtons[0] as TRadioButton).Font.Color=clRed then
Premier:='Vert';
for i:=0 to Nb_BoutonRadio do
begin
if Premier='Vert' then
if i mod 2 = 0 then
(RadioButtons[i] as TRadioButton).Font.Color:=clGreen
else
(RadioButtons[i] as TRadioButton).Font.Color:=clRed
else
if i mod 2 = 0 then
(RadioButtons[i] as TRadioButton).Font.Color:=clRed
else
(RadioButtons[i] as TRadioButton).Font.Color:=clGreen;
end;
end;
// ****************************
procedure TForm1.Button3Click(Sender: TObject);
var i:integer;
begin
for i:=0 to Nb_BoutonRadio do
begin
RadioButtons[i].Free;
end;
SetLength(RadioButtons,0);
RadioGroup1.Height:=30;
Button1.Enabled:=True;
Button2.Enabled:=False;
Button3.Enabled:=False;
end;
procedure TForm1.OnClickRadioButton(Sender: TObject);
begin
ShowMessage('OnClick fonctionne !');
end;
end. |
Partager