如何在Delphi中禁用VCL样式

Ala*_*ark 19 delphi skinning delphi-xe2 vcl-styles

我在Delphi XE2中使用新的VCL样式系统.它工作得很好,但是我想为一个特定的表单禁用它,它上面有许多图像(一个启动/关于表单).问题是我似乎无法找到将其与特定样式相关联的表单属性,因此不能仅为该表单禁用它.似乎只有全局TStyleManager类似乎是静态的.

考虑到这一点,是否只有这样才能实现调用TStyleManager.TrySetStyle('Windows'),显示表单,然后在表单关闭时将其设置回原始样式?

RRU*_*RUZ 25

VCL样式将外观应用于所有VCL应用程序,但您可以禁用特定控件类的VCL样式.因此,如果要为特定表单禁用VCL样式,可以使用RegisterStyleHook传递表单类型的函数和TStyleHook作为空样式挂钩类的类.

这行代码将禁用TFormChild类型的所有形式的VCL样式:

TStyleManager.Engine.RegisterStyleHook(TFormChild, TStyleHook);
Run Code Online (Sandbox Code Playgroud)

现在,如果您运行此代码,表单的所有控件TFormChild仍将使用VCL样式绘制,那么为了解决这个问题,您必须使用像这样的技巧禁用表单所有控件的默认Style钩子

unit uChild;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TButton   = class(Vcl.StdCtrls.TButton); //This declaration is only for disabling the TButton of this form
  TFormChild = class(TForm)
    Button1: TButton;
  private
    { Private declarations }
  public
    { Public declarations }
  end;
Run Code Online (Sandbox Code Playgroud)

现在您可以使用此代码禁用此表单的TButton的VCL样式

TStyleManager.Engine.RegisterStyleHook(uChild.TButton, TStyleHook);
Run Code Online (Sandbox Code Playgroud)

如果您想了解有关使用TStyleHook类的更多信息,请查看文章Exploring Delphi XE2 - VCL样式第二部分.

  • 我知道你有这个问题的解决方案,罗德里戈:)这就是我发布评论而不是答案的原因.干得好 - + 1. (3认同)
  • @Marjan - 它最初是在1998年5月的德尔福杂志上被称为"插入者类".我想现在是时候将它缩写为IC,简称"intersomething class".<G> (2认同)