德尔福:把TImage带到前面 [英] Delphi: Bring TImage to front

查看:169
本文介绍了德尔福:把TImage带到前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看下面的图片:

如您所见,我无法发送按钮回来。这只适用于标签。

As you can see I cannot send Buttons to back. This only works for labels.

那么如何将 TImage 发送到前面的 strong>。

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

顺便说一句,我读了这个相关的问题,但没有帮助我。因为在运行Andreas Rejbrand的代码之后,甚至不能点击按钮。不仅按钮,一切(如图像中的滚动条)

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. Not only buttons, everything (like the scrollbar in this image)

编辑:
我不想让按钮我发送回到图像后可达到。只要把 TImage 带到所有的东西前。

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.

谢谢。

推荐答案

您可以靠近目标的一种方式是使用插入器类作为TWincontrols,并绘制已经被绘制的图像,使用TControlCanvas和钩WM_PAINT。

该代码使用半透明PNG图像显示原始草稿,并可能会被增强。

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.
The code is showing a raw draft using a semitransparent PNG image and may be enhanced.

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.

另一个(更好的)钩的地方将覆盖 PaintWindow 单位Unit2; / p>

Another (better) place to "hook" would be overriding 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.

这篇关于德尔福:把TImage带到前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆