Disposal of only one VCL component in Delphi

I know that you can disable custom styles for components, but how do I enable styles for only one class of components? For example, leave the entire form and all components on it unpainted, and only TButton on the skin. Like in this image.

enter image description here

+6
source share
1 answer

Most VCL controls internally use the global StyleServices function to get methods for drawing a control. Therefore, if you do not use Vcl styles, StyleServices returns an instance in the Windows API functions for drawing thematic controls (UxTheme API). because there is no way to do this (apply Vcl styles) to only one control class (at least you yourself will draw a control).

So the only alternative is to apply Vcl styles and then disable all controls except the one type you are looking for.

You can use something like this

 procedure DisableVclStyles(Control : TControl;const ClassToIgnore:string); var i : Integer; begin if Control=nil then Exit; if not Control.ClassNameIs(ClassToIgnore) then Control.StyleElements:=[]; if Control is TWinControl then for i := 0 to TWinControl(Control).ControlCount-1 do DisableVclStyles(TWinControl(Control).Controls[i], ClassToIgnore); end; 

Verify this form with Vcl style

enter image description here

And now after calling the above method

 DisableVclStyles(Self,'TButton'); 

enter image description here

Note: using the StyleElements property to enable o disable vcl styles does not work with some components (TStringGrid, TBitBtn, TSpeedButton, etc.)

+13
source

All Articles