如何在Delphi中禁用VCL样式

问题描述 投票:19回答:3

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

考虑到这一点,是实现这个的唯一方法来调用TStyleManager.TrySetStyle('Windows'),显示表单,然后在表单关闭时将其设置回原始样式?

delphi delphi-xe2 skinning vcl-styles
3个回答
25
投票

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

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

TStyleManager.Engine.RegisterStyleHook(TFormChild, TStyleHook);

现在,如果您运行此代码表单的所有控件,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;

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

TStyleManager.Engine.RegisterStyleHook(uChild.TButton, TStyleHook);

如果您想了解有关使用TStyleHook类的更多信息,请查看文章Exploring Delphi XE2 – VCL Styles Part II


1
投票

从Splash Form的seClient属性中删除(取消选中)StyleElements选项对我来说很有用(Delphi XE10)。


-2
投票

最简单的方法是将splash-form放在一个单独的DLL中。那样造型师就不会碰它了。

© www.soinside.com 2019 - 2024. All rights reserved.