如何制作firemonkey HUD窗口

时间:2012-01-27 18:30:29

标签: delphi delphi-xe firemonkey hud

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

这就像iPhone中的样子:

HUD

主要问题是如何使表格半透明&完全删除边框。

1 个答案:

答案 0 :(得分:4)

创建Firemonkey HD表单,将其设置为Fill.KindbkNone,将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, label, and rectangle)添加为子组件。然后,使用有效的模式变量调用您创建的过程,它将按照您在代码中指示的方式运行。添加更多模式很容易,我已经使用我自己的应用程序做了类似的事情(虽然它与TRectangle有关,而不是创建指标。)