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

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

问题描述

我在Delphi XE2中使用了新的VCL风格系统。它的功能非常好,但我希望禁用它的一个特定的形式,其上有一些图像(一个飞溅/关于表单)。问题是,我似乎找不到将其与特定样式相关联的窗体的属性,因此无法禁用该窗体。似乎只有全局的 TStyleManager 类似乎是静态的。



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

解决方案

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

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

  TStyleManager.Engine.RegisterStyleHook(TFormChild,TStyleHook); 

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

  unit uChild; 

接口

使用
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); //此声明仅用于禁用此形式的TButton
TFormChild = class(TForm)
Button1:TButton;
private
{私人声明}
public
{公开声明}
end;

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



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

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


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.

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?

解决方案

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.

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

TStyleManager.Engine.RegisterStyleHook(TFormChild, TStyleHook);

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;

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);

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天全站免登陆