gpt4 book ai didi

Delphi:将 TImage 置于前面

转载 作者:行者123 更新时间:2023-12-03 14:55:19 26 4
gpt4 key购买 nike

看下面的图片:

enter image description here

如您所见,我无法将按钮发送到后面。这仅适用于标签。

那么我怎样才能将TImage发送到前面并具有透明度

顺便说一句,我读过 This related question但没有帮助我。因为运行 Andreas Rejbrand 的代码后您甚至无法单击按钮。不仅仅是按钮,所有东西(比如图中的滚动条)

编辑:我不想在将其发送回图像后使该按钮可访问。只是想将 TImage 带到所有内容的前面。

谢谢。

最佳答案

接近目标的一种方法是使用 TWincontrol 的插入器类,并在绘制完它们之后,使用 TControlCanvas 和“ Hook ”WM_PAINT 来绘制在其上移动的图像。
该代码使用半透明 PNG 图像显示原始草稿,并且可能会得到增强。

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.

另一个(更好的)“ Hook ”位置将覆盖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.

关于Delphi:将 TImage 置于前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18925394/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com