举例: 窗体中加入一个Label控件,名为Label1,两个ListBox控件,分别为ListBox1,ListBox2,其中ListBox1用来记录名单,ListBox2用来取得中者名单.{--------生成人名列表用数字作人名为了测试----------} procedure TForm1.Button1Click(Sender: TObject); var i:integer; begin for i :=1 to 50 do begin ListBox1.Items.Add(inttostr(i)); end; end; 抽奖按钮:procedure TForm1.Button2Click(Sender: TObject); var i:integer; begin if ListBox1.Items.Count>0 then begin Randomize; i:=Random(ListBox1.Items.Count-1); ListBox2.Items.Add(ListBox1.Items.Strings[i]); ListBox1.Items.Delete(i); Label1.Caption:=inttostr(strtoint(Label1.Caption)+1); end; end;
窗体中加入一个Label控件,名为Label1,两个ListBox控件,分别为ListBox1,ListBox2,其中ListBox1用来记录名单,ListBox2用来取得中者名单.{--------生成人名列表用数字作人名为了测试----------}
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
for i :=1 to 50 do begin
ListBox1.Items.Add(inttostr(i));
end;
end;
抽奖按钮:procedure TForm1.Button2Click(Sender: TObject);
var
i:integer;
begin
if ListBox1.Items.Count>0 then begin
Randomize;
i:=Random(ListBox1.Items.Count-1);
ListBox2.Items.Add(ListBox1.Items.Strings[i]);
ListBox1.Items.Delete(i);
Label1.Caption:=inttostr(strtoint(Label1.Caption)+1);
end;
end;