无法在运行时更改子窗体的图标



我的应用程序中有一个"搜索和替换"对话框,我想根据表单的模式更改表单的图标,即搜索或替换。

这是我用来配置表单的例程:

procedure TfmFindReplace.SetFormMode(Mode: tConfigMode);
begin
// Set up form for Search or Replace.
if Mode = fcmCurrent then exit;
fFormMode := Mode;
pnlReplaceHldr.Visible := FormMode=fcmReplace;
chkPromptOnReplace.Visible := FormMode=fcmReplace;
rbCurrentProject.Visible := (fmProjManagerVT.IsOpen) and Not (Mode=fcmReplace);
if mode=fcmFind then begin
Caption := 'Find Text';
Icon.LoadFromResourceName(HInstance, 'SEARCH');
image1.Picture.Icon.LoadFromResourceName(HInstance, 'SEARCH')
end
else begin
Caption := 'Replace Text';
Icon.LoadFromResourceName(HInstance, 'REPLACE');
image1.Picture.Icon.LoadFromResourceName(HInstance, 'REPLACE')
end;
end;

我无法更改标题栏上的图标。为了检查我是否从资源文件中提取了图标,我在表单中添加了一个图像,以检查它是否正在重新加载。

我使用的是Delphi 11.1。

我使用的主题似乎正在覆盖设置。(我使用的是Windows11深色和浅色主题(我的工作使表单类型之间的转换相当笨拙,这是:

StyleElements := [seFont,seClient];
if mode=fcmFind then begin
Caption := 'Find Text';
Icon.LoadFromResourceName(HInstance, 'SEARCH');
end
else begin
Caption := 'Replace Text';
Icon.LoadFromResourceName(HInstance, 'REPLACE');
end;
StyleElements := [seFont,seClient,seBorder];

在设置样式元素时,表单会被清除,然后重新绘制。有更清洁的解决方案吗?

最新更新