如何在 Delphi 中禁用 VCL 样式 [英] How to disable VCL styles in Delphi

查看:24
本文介绍了如何在 Delphi 中禁用 VCL 样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using the new VCL styles system in Delphi XE2. It works great, but I wish to disable it for a particular form that has a number of images on it (a splash/about form). Problem is I can't seem to find a property of the form that associates it with a particular style, and so can't disable it for that form only. There only seems to be the global TStyleManager class which appears to be static.

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

With this in mind, is the only way to achieve this to call TStyleManager.TrySetStyle('Windows'), show the form, and then set it back to the original style when the form is closed?

推荐答案

VCL 样式将皮肤应用于所有 VCL 应用程序,但您可以禁用特定控件类的 VCL 样式.因此,如果您想禁用特定表单的 VCL 样式,您可以使用 RegisterStyleHook 函数传递表单的类型和 TStyleHook 类,这是一个空样式钩子类.

The VCL Styles apply a skin to all of the VCL application, but you can disable the VCL Styles for a particular control class. So if you want disable the VCL Styles for a particular form, you can use the RegisterStyleHook function passing the type of the form and the TStyleHook class which is a empty style hook class.

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

This line of code will disable the VCL Styles in all the forms of the type TFormChild:

TStyleManager.Engine.RegisterStyleHook(TFormChild, TStyleHook);

现在,如果您运行此代码表单的所有控件,TFormChild 仍将使用 VCL 样式绘制,因此要修复您必须禁用表单所有控件的默认样式挂钩使用这样的技巧

Now, if you run this code all controls of the form, TFormChild will still painted with the VCL Styles, so to fix that you must disable the default Style hook for all the controls of the form using a trick like this

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 样式

and now you can disable the VCL Styles of the TButton of this form as well with this code

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

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

If you want more information about the use of the TStyleHook Class, check the article Exploring Delphi XE2 – VCL Styles Part II.

这篇关于如何在 Delphi 中禁用 VCL 样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆