gpt4 book ai didi

image - Delphi:如何在单击按钮数组时制作程序?

转载 作者:行者123 更新时间:2023-12-03 18:42:15 24 4
gpt4 key购买 nike

我必须在Delphi中进行项目。我做了一个按钮数组和一个图像数组。当我单击按钮[i]时,我想显示图像[i]。

有人可以帮忙吗?

最佳答案

如何使用按钮的tag属性存储指向相关图像的指针。我不确定您的Array结构,但这是一个演示代码段。

TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
Button2: TButton;
Image2: TImage;
procedure FormCreate(Sender: TObject);

private
FMyCurrentImage : TImage; //Keeps track of the current image
procedure MyButtonClick(Sender: TObject);
public

end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
FMyCurrentImage := nil;

Button1.Tag := Integer(Image1);
Button1.OnClick := MyButtonClick;
Image1.Hide;

Button2.Tag := Integer(Image2);
Button2.OnClick := MyButtonClick;
Image2.Hide;
end;

procedure TForm1.MyButtonClick(Sender: TObject);
begin
if Sender is TButton then
with Sender as TButton do
if Assigned(TImage(Tag)) then
begin
//Hide the previously selected image
if Assigned(FMyCurrentImage) then
FMyCurrentImage.Hide;

//Assign and show the clicked button's image
FMyCurrentImage := TImage(Tag);
FMyCurrentImage.Show;
end;
end;

关于image - Delphi:如何在单击按钮数组时制作程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16775564/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com