19

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?

RRUZ
  • 134,889
  • 20
  • 356
  • 483
Alan Clark
  • 2,017
  • 21
  • 28
  • AFAICT, with the new `Styles` it's all or nothing. IOW, if you use `Styles`, they apply to every single form in your app, and there's no way to selectively enable/disable them on a per-form basis. – Ken White Dec 22 '11 at 02:23

3 Answers3

27

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • Just an additional Note : the above answer only covers the controls inherited of the `TWinControl` class, also some controls will require which you create a custom a TStyle Hook class to ignore the current style. – RRUZ Dec 22 '11 at 03:11
  • 3
    I knew you'd have a solution for this issue, Rodrigo :) That's why I posted a comment instead of an answer. Nice work - +1. – Ken White Dec 22 '11 at 04:10
  • Nice going, works great, except for TPanel. The interpolator for TButton as in the example works, but an interpolated TPanel seems to still be painted using the style, AFAICT. Any idea why? – Alan Clark Dec 22 '11 at 06:45
  • 1
    @AlanClark You had me searching for what an 'Interpolator' is, until I realized you meant an Interceptor class... At least that is how I know the concept and have heard it talked about :) – Marjan Venema Dec 22 '11 at 09:59
  • 2
    @Marjan - Yet it was originally coined up as an "interposer class" in May 1998 issue of the delphi magazine. I guess it is time that we abbreviate it as an IC, shorthand for "intersomething class". – Sertac Akyuz Dec 22 '11 at 14:18
  • 1
    @Sertac: Thanks for the history. Didn't know that. Abbreviating it sounds good to me :) – Marjan Venema Dec 22 '11 at 15:38
  • @MSertac Interposer! That's correct, I had a case of verbal diarrhea there. Interceptor also works. – Alan Clark Dec 22 '11 at 20:11
  • This does NOT work for me on anything that inherits from TEdit, or on TStringGrid. – Warren P Feb 03 '12 at 20:46
  • @WarrenP, exists some controls which requires of more work to disable the vcl styles. – RRUZ Feb 04 '12 at 22:57
  • That would be a great topic for a blog post if anybody can provide a way to disable it. Or I'll ask the question.... – Warren P Feb 06 '12 at 14:23
  • @WarrenP check this article [Changing the color of Edit Controls with VCL Styles Enabled](http://theroadtodelphi.wordpress.com/2012/02/06/changing-the-color-of-edit-controls-with-vcl-styles-enabled/) – RRUZ Feb 06 '12 at 18:13
  • Thanks. THat link helped me answer this question: http://stackoverflow.com/questions/9130945/delphi-xe2-disabling-vcl-style-on-a-component – Warren P Feb 06 '12 at 20:42
4

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

-1

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

Pieter B
  • 1,874
  • 10
  • 22
  • 3
    Hardly easy. Then you also have to check if the DLL exists, if the proc's line up, and also add extra work to the installer. Surely its easier to add X number of sourcelines and be done with it :) – Jon Lennart Aasenden Feb 04 '12 at 19:29
  • Why downvote? Seem totally reasonable to me if that solves the problem! – Totte Karlsson May 21 '17 at 23:53
  • Probably the down-votes are because of the "The easiest way" phrase. This is valid answer but definitively not the 'easy way'. – Gabriel Feb 18 '18 at 19:11