本文介绍了像TPanel这样的控件可以放在顶部吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序正在执行一项耗时的任务,我想在应用程序窗口的中间显示一个TImage,但它不会停留在顶部-我的VST始终位于顶部。但是,当我使用TPanel时,它停留在顶部吗?我该如何使TImage做到这一点?

My program is doing a time consuming task, and I would like to display a TImage in the middle of the application window, but it will not stay on top - my VST is always on top. However, when I use a TPanel, it stays on top? How can I make my TImage do that?

实际上,适用于所有控件的解决方案非常出色:)

In fact, a solution that applies to all controls would be splendid :)

谢谢!

推荐答案

您需要一个带窗口的控件(即带有窗口句柄或适当控件)来显示您的消息,因为在窗口控件上方无法看到非窗口控件。最简单的解决方案是将 TImage 放在 TPanel 中,并设置 Image1.Align:= alClient Panel1.BorderStyle:= bsNone

You need a windowed control (that is, a control with a window handle, or a "proper" control) to display your message, because a non-windowed control cannot be visible above a windowed control. The easiest solution is to place the TImage in a TPanel and set Image1.Align := alClient and Panel1.BorderStyle := bsNone.

如果您想绘制一个半透明位图位于普通控件的顶部,您可以像我经常做的那样:

If you wish to draw a semi-transparent bitmap on top of your ordinary controls, you can do like I always do:

procedure TForm1.Button1Click(Sender: TObject);
var
  bm: TBitmap;
  png: TPngImage;
begin
  // The form contains a hidden TPanel (somewhere on the form)
  // with a TImage (alClient).

  // png is a PNG image with an alpha channel
  png := TPngImage.Create;
  try
    png.LoadFromFile('C:\Users\Andreas Rejbrand\Pictures\alpha.png');
    // Create bitmap of form and blend PNG on it
    bm := GetFormImage;
    try
      bm.Canvas.Draw(0, 0, png);
      Image1.Picture.Bitmap := bm;
    finally
      bm.Free;
    end;
    Panel1.Align := alClient;
    Panel1.BringToFront;
    Panel1.Show;
  finally
    png.Free;
  end;
end;

这篇关于像TPanel这样的控件可以放在顶部吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 06:58