gpt4 book ai didi

delphi - delphi组件顺序和图层选项

转载 作者:行者123 更新时间:2023-12-03 18:23:29 24 4
gpt4 key购买 nike

我是delphi编程的新手:(
我正在尝试制作具有透明背景层和圆形顶层的自定义组件。但是,将以下代码添加到表单时,效果很好。
除了存在另一个组件的事实与自定义组件重叠或位于其之上之外,它位于下方且未显示。
我在下面尝试过一种形式

 BadgeTest1.BringToFront;
BadgeTest1.ComponentIndex:=2;
IndexVal:= BadgeTest1.ComponentIndex;


但是,仍然不起作用。无论如何,自定义组件是否可以显示在其他组件之上?只有圆形部分?
另外,我一直在尝试在自定义组件的中心(水平和垂直)放置标题,并尝试使用TextOut()过程。如果有更好的选择,请让我知道吗?
以下是我的自定义组件BadgeTest的代码。
请帮忙,
非常感谢!

type
TBadgeTest=class(TGraphicControl)

private
FCaption:TCaption;
FColor:TColor;
FLayers:TLayerCollection;
FHeight:Integer;
FWidth:Integer;

protected
procedure Paint; override;
procedure SetBkgLayer;
procedure SetSecondLayer;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Caption:TCaption read FCaption write FCaption;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Sample', [TBadgeTest]);
end;

constructor TBadgeTest.Create(AOwner: TComponent);
var
ACanvas:TcxCanvas;
begin
inherited;
FHeight:=20;
Self.Height:=FHeight;
Constraints.MaxHeight:=20;
Constraints.MinHeight:=20;
FHeight:=20;
Self.Width:=FWidth;
Constraints.MaxWidth:=20;
Constraints.MinWidth:=20;
end;

destructor TBadgeTest.Destroy;
begin
inherited;
end;

procedure TBadgeTest.SetBkgLayer;
var
Bitmap:TBitmap32;
Layer: TCustomLayer;
begin
FLayers := TLayerCollection.Create(Self);
Layer := FLayers.Add(TBitmapLayer);
Layer.Index:=0;
Bitmap:= TBitmap32.Create;
Bitmap.DrawMode:=dmOpaque;
Bitmap.SetSize(Width, Height);
Bitmap.clear($00000000);

Bitmap.Canvas.Pen.Width:=0;
Bitmap.Canvas.Brush.Color:=$00107EFF;
Bitmap.Canvas.Brush.Style:=bsClear;
Bitmap.Canvas.Ellipse(Rect(0,0,20,20));
end;

procedure TBadgeTest.SetSecondLayer;
var
Bitmap:TBitmap32;
Layer: TCustomLayer;
begin
Layer := FLayers.Add(TBitmapLayer);
Layer.Index:=1;
Layer.LayerOptions:= LOB_VISIBLE;
Bitmap:=TBitmap32.Create;
Bitmap.DrawMode:=dmCustom;
Bitmap.SetSize(Width, Height);
Bitmap.clear($00000000);

Bitmap.Canvas.Pen.Width:=0;
Bitmap.Canvas.Brush.Color:=$00107EFF; //FF7E10
Bitmap.Canvas.Brush.Style:=bsSolid;
Bitmap.Canvas.Ellipse(Rect(0,0,Self.Width,Self.Height));

Layer.BringToFront;
Layer.BringToFront;
//Layer.Scaled:=true;
// Layer.Bitmap:=Bitmap;
end;

procedure TBadgeTest.Paint;
var
R:TRect;
borderColor : Integer;
fillCircle : Integer;
fontColor : Integer;
fontSize : Integer;
Bitmap:TBitmapImage;
const
_FF7E10_COLOR:Integer = $00107EFF; //#FF7E10

begin
inherited;
borderColor:=_FF7E10_COLOR;
fillCircle:=_FF7E10_COLOR;

Canvas.Pen.Create;
Canvas.Pen.Style:=psClear;
Canvas.Pen.Color:=borderColor;
Canvas.Pen.Width:=0;

SetBkgLayer;
SetSecondLayer;

Canvas.Brush.Create;
Canvas.Brush.Style:= bsClear;
Canvas.Brush.Color:=fillCircle;
Canvas.Ellipse(0,0,Self.Width,Self.Height);
Canvas.Font.Color:=clWhite;
Canvas.Font.Name:='Arial';
Canvas.Font.Size:=8;
Canvas.Font.Quality := fqNonAntialiased;
Canvas.Font.Style := [fsBold];

R.Create(0, 0, Self.Width, Self.Height);
//DrawText(Canvas.Handle, PChar(FCaption), -1, R, vaCenter);
// Canvas.DrawText(FCaption, R, taCenter, vaCenter, False, False);
Canvas.TextOut(5, 5, FCaption);
//SetTextAlign(Canvas.Handle, ta_center);
//DrawText(Canvas.Handle, PChar(FCaption),
//R.Create(1, 10, 2, 26);
// Self.Width := Canvas.TextWidth(FCaption) + 30;
end;

最佳答案

TGraphicControl没有窗口句柄,仅在其父DC上绘制。
您不能将TGraphicContol放在TWinContol后代(例如TPanelTButtonTEdit等)的前面。

请使用可以放在其他子TWinControl前面的TWinControl descendant as shown in your previous question,或以避免出现其他TWinControl与自定义图形控件重叠或重叠的方式重新设计UI。

P.S:视觉控件被称为“控件”,而不是“组件”(非视觉)

关于delphi - delphi组件顺序和图层选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27124526/

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