德尔福组件顺序和层选项



我对德尔福编程很陌生:(我正在尝试制作一个具有透明背景层和具有圆形的顶层的自定义组件。但是,下面的代码在添加到窗体中时工作正常。例外,即有另一个组件与自定义组件重叠或位于自定义组件之上,它位于下方并且不显示。我在下面的表格上尝试过

 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前面,或者重新设计UI,以消除另一个TWinControl与自定义图形控件重叠或位于自定义图形控件之上的情况。

附言:可视控件称为"控件

",而不是"组件"(非可视控件)

最新更新