Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 如何在VCL样式的页面控件上绘制所有者_Delphi_Canvas_Delphi 10 Seattle_Ownerdrawn_Tpagecontrol - Fatal编程技术网

Delphi 如何在VCL样式的页面控件上绘制所有者

Delphi 如何在VCL样式的页面控件上绘制所有者,delphi,canvas,delphi-10-seattle,ownerdrawn,tpagecontrol,Delphi,Canvas,Delphi 10 Seattle,Ownerdrawn,Tpagecontrol,当我有这个: if not _nightMode then TStyleManager.TrySetStyle('Windows', False); if _nightMode then TStyleManager.TrySetStyle('Cobalt XEMedia', False); 我可以在页面控件上绘制所有者: procedure TMyMainForm.pcDetailedDrawTab(Control: TCustomTabControl; TabIndex: Inte

当我有这个:

if not _nightMode then
  TStyleManager.TrySetStyle('Windows', False);
if _nightMode then
  TStyleManager.TrySetStyle('Cobalt XEMedia', False);
我可以在页面控件上绘制所有者:

procedure TMyMainForm.pcDetailedDrawTab(Control: TCustomTabControl; TabIndex: Integer;
    const Rect: TRect; Active: Boolean);
var
  can: TCanvas;
  cx, by: Integer;
  aclr: TColor;
begin
  if pcDetailed.Pages[TabIndex] = tsActualData then begin
    can := pcDetailed.Canvas;
    cx := Rect.Left + Rect.Width div 2;
    by := Rect.Bottom - 2;
    if _nightMode then aclr := clWhite else aclr := clBlack;
    can.Pen.Color := aclr;
    can.Brush.Color := aclr;
    can.Polygon([Point(cx - 10, by - 10), Point(cx + 10, by - 10), Point(cx, by)]);
  end;
end;
当我有这个:

if not _nightMode then
  TStyleManager.TrySetStyle('Windows', False);
if _nightMode then
  TStyleManager.TrySetStyle('Cobalt XEMedia', False);
我画的三角形丢失了

如何使用任何VCL样式绘制三角形

Delphi 10西雅图。

当选择本机“Windows”样式以外的样式时,
StyleHook
-类将开始将相关的Windows消息钩住控件。对于不同的控件类,有不同的
StyleHook

对于
TPageControl
而言,它是
TTabControlStyleHook
。钩子类组合在
TCustomStyleEngine.RegisterStyleHook(TCustomTabControl,TTabControlStyleHook)中注册TCustomTabControl
的类构造函数中的code>。这个钩子类正在重写控件绘制,因为当启用样式时,它将绘制
TCustomTabControl
本身

可以做的是取消注册默认的
TStyleHookClass
,并注册一个允许开发人员绘制的类:

  TCustomStyleEngine.UnRegisterStyleHook(TCustomTabControl, TTabControlStyleHook);
  TCustomStyleEngine.RegisterStyleHook(TCustomTabControl, TMyTabControlStyleHook);
其中
TMyTabControlStyleHook
如下所示:

type
  TMyTabControlStyleHook = class(TTabControlStyleHook)
  public
    constructor Create(AControl: TWinControl); override;
  end;

constructor TMyTabControlStyleHook.Create(AControl: TWinControl);
begin
  inherited Create(AControl);
  OverridePaint := False;
end;
但是,这并不完全等同于仅绘制
TPageControl
中的选项卡,因为
tPabControl样式挂钩
负责绘制完整的
TPageControl
控件

但是
TTabControlStyleHook
procedure-DrawTab(Canvas:TCanvas;Index:Integer);虚拟的,可以为此重写它

type
  TMyTabControlStyleHook = class(TTabControlStyleHook)
  strict protected
    procedure DrawTab(Canvas: TCanvas; Index: Integer); override;
  end;

procedure TMyTabControlStyleHook.DrawTab(Canvas: TCanvas; Index: Integer);
begin
  DrawTabOverride(Canvas, Index, TabRect[Index], TCustomTabControl(Control).MouseInClient);
end;
其中
DrawTabOverride
是这样的

procedure DrawTabOverride(Canvas: TCanvas;
  TabIndex: Integer; const Rect: TRect; Active: Boolean);

因此,当绘制本机时,可以在
OnDrawTab
事件中调用它,当设置样式时,可以在StyleHook类
DrawTab
中调用它

这是VCL风格,而不是主题。而德尔菲的版本通常对这些问题很重要。