简体   繁体   English

德尔福:将TImage带到前面

[英]Delphi: Bring TImage to front

Look at the image below: 看下图:

在此输入图像描述

As you can see I cannot send Buttons to back. 如你所见,我无法发回按钮。 This only works for labels. 这仅适用于标签。

So how can I send TImage to front with its transparency . 那么我怎么能以透明的方式TImage发送到前面。

By the way I've read This related question but didn't help me. 顺便说一句,我读过这个相关的问题,但没有帮助我。 Because you cannot even click on a button after running Andreas Rejbrand's code. 因为在运行Andreas Rejbrand的代码后你甚至无法点击按钮。 Not only buttons, everything (like the scrollbar in this image) 不仅按钮,一切(如此图像中的滚动条)

Edit: I don't want to make the button reachable after I send that back to the image. 编辑:我发送回图像后,我不想让按钮可以访问。 Just want to bring TImage to front of everything. 只想把TImage带到一切的前面。

Thanks. 谢谢。

One way which could you near the goal would be to use interposer classes for the TWincontrols and paint the image moved on them, after they have been painted already, using a TControlCanvas and "hooking" WM_PAINT. 你可以接近目标的一种方法是使用插入器类进行TWincontrols,并在使用TControlCanvas并“挂钩”WM_PAINT后绘制已经绘制的图像。
The code is showing a raw draft using a semitransparent PNG image and may be enhanced. 该代码使用半透明PNG图像显示原始草稿,并且可以进行增强。

在此输入图像描述

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" would be overriding PaintWindow 另一个(更好)“挂钩”的地方将覆盖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.

You do not want the Image brought to front (which by the way is impossible over a windowed control), because you want the button also reachable. 你不希望图像被带到前面(顺便说一句,在窗口控件上是不可能的),因为你希望按钮也可以访问。

Although your question is contradicting itself, and it is not at all clear what exactly you want to achieve, I think you mean to have a transparent button over an image. 虽然你的问题本身就是矛盾的,但是你完全不知道你想要实现什么,我认为你的意思是在图像上有一个透明的按钮。

If so, then use a TSpeedButton , and set its Transparent and Flat property to True. 如果是,则使用TSpeedButton ,并将其TransparentFlat属性设置为True。

Here an example with the three button states: normal, hovered, pressed: 这里有一个带有三个按钮状态的示例:正常,悬停,按下:

在此输入图像描述

You can use the solution you linked in your question. 您可以使用您在问题中链接的解决方案。 For the controls that you want the clicks go through - disable them. 对于您希望点击进行的控件 - 禁用它们。 Since you're putting the image on a panel, disabling both the panel and the image will let the button to be clicked. 由于您将图像放在面板上,因此禁用面板和图像将使按钮被单击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM