سؤال

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.

نصائح أخرى

Removing (uncheck) the seClient option from the StyleElements property of the Splash Form did the trick for me (Delphi XE10).

The easiest way is to put the splash-form in a seperate DLL. That way the styler won't touch it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top