参考一下,按数字键隐藏Button:procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var i:integer; begin for i:=0 to self.ComponentCount-1 do if self.Components[i] is TButton then begin if Pos(IntToStr(Key-48),Components[i].Name)>0 then TButton(Components[i]).Enabled:=False else TButton(Components[i]).Enabled:=True; end; end;procedure TForm1.FormCreate(Sender: TObject); begin Form1.KeyPreview:=True; end;
汗,应该是Visible if Pos(IntToStr(Key-48),Components[i].Name)>0 then TButton(Components[i]).Visible:=True else TButton(Components[i]).Visible:=False;
如:
button1.visible:=True;
button2.visible:=False;
2 要显示的 visible:=true
Shift: TShiftState);
var i:integer;
begin
for i:=0 to self.ComponentCount-1 do
if self.Components[i] is TButton then
begin
if Pos(IntToStr(Key-48),Components[i].Name)>0 then
TButton(Components[i]).Enabled:=False
else
TButton(Components[i]).Enabled:=True;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.KeyPreview:=True;
end;
if Pos(IntToStr(Key-48),Components[i].Name)>0 then
TButton(Components[i]).Visible:=True
else
TButton(Components[i]).Visible:=False;