Controls on top, like TPanel can do?
Asked Answered
S

2

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!

Supporter answered 20/3, 2011 at 16:12 Comment(2)
@LachlanG: Virtual StringTree, a very well-known 3rd-party control.Possing
Thanks Andreas. I know the control, should have guessed the acronym.Kingsize
P
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

Possing answered 20/3, 2011 at 16:16 Comment(10)
I thought about that too, however my image has alphablended borders. +1 for the info though!Supporter
@Andreas Can you tell Jeff how to make his panel transparent?Andradite
@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.Possing
@Andreas yeah, it's not my area of expertise eitherAndradite
@David: I added a piece of code that amounts to the same thing, at least. And this code is perfectly robust.Possing
A TPanel is already transparent when themes are enabled and 'ParentBackground' is True (default), no?Islington
@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.Possing
@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? :)Supporter
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.Abuttal
@Rob: True, of course. IIRC, other answers (maybe even by myself) does what you talk about. Layered windows, and stuff like that.Possing
A
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?

Andradite answered 20/3, 2011 at 16:16 Comment(1)
Yes, but I would prefer to have it visible.Supporter

© 2022 - 2024 — McMap. All rights reserved.