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
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, OleCtrls, SHDocVw, HTTPApp;
type
TForm1 = class(TForm)
Label1: TLabel;
ListBox1: TListBox;
choix: TButton;
Button1: TButton;
procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure choixClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
t: array[0..9] of string=('HNO3','H2SO4','FeSO4','O2','CH4','H2O','Fe6','C3H6O',
'C6H6','C6H1206');
implementation
uses Unit2;
{$R *.DFM}
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
const num = ['1'..'9'];
var Texte : string; c : Char; i,w,h : byte; x,y : integer;
begin ListBox1.Style:=(lbOwnerDrawFixed);
with ListBox1.Canvas do
begin Font.Color:=clBlack; // Couleur de fonte
if Odd(Index) then Brush.Color:=clAqua // Couleur d'arrière plan
else Brush.Color:=clWhite; // alternée bleu/blanc
FillRect(Rect); // Remplit le rectangle de l'Index sur canvas avec Brush.color
// Texte de l'Item
Texte:=ListBox1.Items[0];
Font.name:='Arial';
x:=Rect.Left+3; y:=Rect.Top;
for i:=1 to length(Texte) do
begin c:=Texte[i];
if Not (c in Num) then // Symboles en position normale
begin Font.Size:=12;
TextOut(x, y, c);
w:=TextWidth(c); x:=x+w;
end else // indices numériques
begin Font.Size:=8; h:=TextHeight(c);
TextOut(x, Rect.Bottom - h, c);
w:=TextWidth(c); x:=x+w;
end;
end;
end;
end;
procedure TForm1.choixClick(Sender: TObject);
var
z:integer;
begin
randomize;
z:=random(10);
Listbox1.Items.Add(t[z]) ;
ListBox1DrawItem(ListBox1,z,ListBox1.ItemRect(0),[odDefault]);
choix.visible:=false;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
form2.show;
end;
end. |
Partager