如何制作 firemonkey HUD 窗口

发布于 2024-12-29 09:35:43 字数 268 浏览 1 评论 0原文

我想在 Delphi 中复制 https://github.com/jdg/MBProgressHUD 的 HUD 功能火猴。

这是 iPhone 中的样子:

HUD

主要问题是如何使表单半透明和半透明。完全去除边框。

I wanna to replicate the HUD functionality of https://github.com/jdg/MBProgressHUD in Delphi with firemonkey.

This is what look like in iPhone:

HUD

The main issue is how make the form semi-transparent & completely remove the borders.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疾风者 2025-01-05 09:35:43

创建 Firemonkey HD 表单,将其 Fill.Kind 设置为 bkNone,将 Fill.Color 设置为 Null。此外,将其 Transparency 属性设置为 True,将 BorderStyle 设置为 bsNone

创建一个 TRectangle(或任何形状),并将 Stroke.Kind 属性设置为 bkNone。将其Fill.Color设置为Gray,将Opacity设置为0.5。

创建一个 TAniIndicatorTLabel,并将两者的父级作为表单。它的Opacity 保持为 1.0。或者,还可以创建一个 TImage 并使其大小和位置与 TAniIndicator 完全相同。

从那里开始,当您想要更改图像(为勾号等)和标签文本以更改为您想要显示的任何消息时,只需在 TAniIndicator 上使用 TFloatAnimation 即可。理想情况下,您只需创建一个接受字符串或整数作为变量的过程,然后修改文本和指示器/图像以匹配它。例如;

Procedure TForm1.Process(Mode : Integer);
Begin
 if Mode = 1 then
 begin
  AniIndicator1.Enabled := True;
  AniIndicator1.Visible := True;
  Image1.Visible := False;
  Label1.TextAlign := TTextAlign.taCenter; // Must be called to reset alignment
  Label1.Text := 'Loading';
 End
 else if Mode = 2 then
 Begin
  AniIndicator1.Enabled := False;
  AniIndicator1.Visible := False;
  Label1.TextAlign := TTextAlign.taCenter; // Must be called to reset alignment
  Image1.Bitmap.LoadFromFile('Tick.png');
  Image1.Visible := True;
  Label1.Text := 'Complete!';
 end;
end;

然后,您可以在主窗体中创建一个 tpanel,然后添加上述窗体(包含 TAniIndicator、标签和矩形)作为子组件。然后,您使用有效的模式变量调用您创建的过程,它将按照您在代码中指示的方式运行。添加更多模式非常容易,我已经对自己的一个应用程序做了类似的操作(尽管它与 TRectangle 相关,而不是创建指标)。

Create your Firemonkey HD form, set it's Fill.Kind to bkNone, and it's Fill.Color to Null. Additionally, set it's Transparency property to True, and it's BorderStyle to bsNone.

Create a TRectangle (or any shape), and set the Stroke.Kind property to bkNone. Set it's Fill.Color to Gray, it's Opacity to 0.5.

Create a TAniIndicator and TLabel with parent of both as the form. It's Opacity remains at 1.0. Optionally, also create a TImage and make it the exact same size and position as the TAniIndicator.

From there, it's simply a case of working with TFloatAnimation on the TAniIndicator when you want to change the image (to a tick or such) and the label text to simply change to whatever message you want to display. Ideally, you simply create a procedure that accepts either a string or integer as a variable, and then modify the text and indicator/image to match that. For example;

Procedure TForm1.Process(Mode : Integer);
Begin
 if Mode = 1 then
 begin
  AniIndicator1.Enabled := True;
  AniIndicator1.Visible := True;
  Image1.Visible := False;
  Label1.TextAlign := TTextAlign.taCenter; // Must be called to reset alignment
  Label1.Text := 'Loading';
 End
 else if Mode = 2 then
 Begin
  AniIndicator1.Enabled := False;
  AniIndicator1.Visible := False;
  Label1.TextAlign := TTextAlign.taCenter; // Must be called to reset alignment
  Image1.Bitmap.LoadFromFile('Tick.png');
  Image1.Visible := True;
  Label1.Text := 'Complete!';
 end;
end;

You can then create a tpanel in your main form, and then add the above form (that contains the TAniIndicator, label, and rectangle) as a child component. You then call the procedure you created with a valid mode variable and it'll run as you indicated in the code. It's easy enough to add more modes and i've done something similar with one of my own applications (although it was related to TRectangle rather than creating an indicator).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文