Delphi: Bring TImage Forward

Take a look at the image below:

enter image description here

As you can see, I can not send the buttons back. This only works for shortcuts.

So how can I send the TImage to the front with its transparency .

By the way, I read this related question , but did not help me. Because you canโ€™t even press a button after running the code of Andreas Reggrand. Not just buttons, everything (e.g. the scroll bar in this image)

Edit: I do not want to make the button available after I send it back to the image. I just want to bring TImage to everyone.

Thanks.

+6
source share
3 answers

One way you could get closer to your goal is to use the intermediate element classes for TWincontrols and draw the image moved onto them after they have already been painted using TControlCanvas and WM_PAINT hooking.
The code shows an unprocessed draft using a translucent PNG image and can be enlarged.

enter image description here

 unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, dxGDIPlusClasses, ExtCtrls; type TButton=Class (StdCtrls.TButton) Procedure WMPaint(var MSG:TMessage);Message WM_Paint; End; TEdit=Class (StdCtrls.TEdit) Procedure WMPaint(var MSG:TMessage);Message WM_Paint; End; TForm2 = class(TForm) Image1: TImage; SpeedButton1: TSpeedButton; Button1: TButton; Edit1: TEdit; Edit2: TEdit; private { Private-Deklarationen } public { Public-Deklarationen } end; var Form2: TForm2; implementation {$R *.dfm} { TButton } procedure TButton.WMPaint(var MSG: TMessage); var cc:TControlCanvas; begin inherited; CC:=TControlCanvas.Create; CC.Control := TControl(Self); CC.Draw(-Left,-Top,Form2.Image1.Picture.Graphic); CC.Free; end; procedure TEdit.WMPaint(var MSG: TMessage); var cc:TControlCanvas; begin inherited; CC:=TControlCanvas.Create; CC.Control := TControl(Self); CC.Draw(-Left,-Top,Form2.Image1.Picture.Graphic); CC.Free; end; end. 

Another (better) place to hook will override PaintWindow

 unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, dxGDIPlusClasses, ExtCtrls; type TButton=Class (StdCtrls.TButton) procedure PaintWindow(DC: HDC);override; End; TEdit=Class (StdCtrls.TEdit) procedure PaintWindow(DC: HDC);override; End; TForm2 = class(TForm) Image1: TImage; SpeedButton1: TSpeedButton; Button1: TButton; Edit1: TEdit; Edit2: TEdit; private { Private-Deklarationen } public { Public-Deklarationen } end; var Form2: TForm2; implementation {$R *.dfm} { TButton } procedure TButton.PaintWindow(DC: HDC); var cc:TCanvas; begin inherited; CC:=TCanvas.Create; CC.Handle := DC; CC.Draw(-Left,-Top,Form2.Image1.Picture.Graphic); CC.Free; end; procedure TEdit.PaintWindow(DC: HDC); var cc:TCanvas; begin inherited; CC:=TCanvas.Create; CC.Handle := DC; CC.Draw(-Left,-Top,Form2.Image1.Picture.Graphic); CC.Free; end; end. 
+10
source

You donโ€™t want the image to be brought to the front (which, by the way, is not possible with the window control), because you want the button to be reachable as well.

Although your question contradicts itself, and it is not at all clear what exactly you want to achieve, I think you mean the transparent button above the image.

If so, use TSpeedButton and set the Transparent and Flat property to True.

Here is an example with three button states: normal, hovering, pressed:

enter image description here

+8
source

You can use the solution that you linked in your question. For the controls you want, clicks go through - turn them off. As you place the image on the panel, disabling the panel and the image will allow the click of a button.

+4
source

Source: https://habr.com/ru/post/954293/


All Articles