2

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 :)

Thanks!

Jeff
  • 12,085
  • 12
  • 82
  • 152

2 Answers2

10

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;

Sample result

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • I thought about that too, however my image has alphablended borders. +1 for the info though! – Jeff Mar 20 '11 at 16:17
  • @Andreas Can you tell Jeff how to make his panel transparent? – David Heffernan Mar 20 '11 at 16:20
  • @David: Am I afraid that I know of no robust method of achieving this. (I guess you'd add `WS_EX_TRANSPARENT` and respond to some messages.) Please enlighten us if you do. – Andreas Rejbrand Mar 20 '11 at 16:31
  • 1
    @Andreas yeah, it's not my area of expertise either – David Heffernan Mar 20 '11 at 16:39
  • @David: I added a piece of code that amounts to the same thing, at least. And this code is perfectly robust. – Andreas Rejbrand Mar 20 '11 at 16:43
  • A TPanel is already transparent when themes are enabled and 'ParentBackground' is True (default), no? – Sertac Akyuz Mar 20 '11 at 16:51
  • @Sertac: Create a new VCL form, and add ten `TEdit` controls all around it. Now, drop a `TPanel` on the form, and let it cover most of the edits. Run the project. Now you don't see the edits behind the panel. So in *this* sense, it is *not* transparent. – Andreas Rejbrand Mar 20 '11 at 17:03
  • @Andreas - The thing is, I wish to use my Image as a "sort of panel", because I will be storing a label on it, that displays a message. Is that possible with the code you provided? :) – Jeff Mar 21 '11 at 13:26
  • While the panel is in front, you can't actually use the mouse to interact with the other controls, can you? The effect you're demonstrating is purely *visual*, right? That's probably fine for Jeff when he wants to effectively disable access to other controls while the time-consuming operation is active, but not suitable for just *generally* displaying an image in front of other controls. – Rob Kennedy Sep 20 '13 at 20:49
  • @Rob: True, of course. IIRC, other answers (maybe even by myself) does what you talk about. Layered windows, and stuff like that. – Andreas Rejbrand Sep 20 '13 at 21:56
1

A TImage does not have a window associated with it and that's the difference between it and the panel.

Add a panel, and put the image inside the panel, i.e. the image's parent is the panel. Then you can bring the image to the front by bringing the panel to the front.

Did you think about hiding your VST?

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490