Delphi VCL Style Tutorial – How to Change Style at runtime

Is there a good VCL style tutorial where we see how to load/change styles dynamically (at runtime)?

This should work for Delphi XE2 and higher, because XE2 is the first version with VCL style.

I’m adding an answer because local information is usually more popular than links.

The following are the key things you need to know before you start Facts:

>Many VCL controls have color attributes, but when the style is turned on, these attributes will be ignored, and the default “common controls” like Button will be drawn by Delphi itself instead of using “or” “. Comes with a window”.
>Somehow, deep in your application, the VCL style will introduce some hooks to take over drawing your control. Everything it can handle will use the “at the top of the regular control” “Skin” drawing. Many people call it “skinning vcl”. Before the VCL style, you may have found a third-party skin system. Now it is built-in.
>Anything without hooks will still get the regular style. So most third-party controls, as well as some bits of VCL are not the subject. Don’t expect perfect instant results. In addition, you may sometimes see some flashes or glitches caused by skinning, which is to be expected. When adding style loading, the final quality of the result is anyone’s guess. You can’t necessarily guarantee that the style loaded at runtime will contain everything you might want it to contain. You also can’t guarantee that one will be statically included in your application. , But at least the ones you statically include can be verified by your QA team (probably you).

This is the easiest step to start: really only steps #2 to #4 are essential .

>Click File -> New -> VCL Form Project.
>Right-click the project option in the “Project Manager” pane, and click “Properties”. Navigate to the application Program -> appears
>Click on the custom style to open it. (Amakrits is the first in my list, so I will click on it).
>Click on the default style combo box and change it to Values ​​other than the default values.
>Put something on the form so that it won’t be empty. (Buttons, list boxes, etc.).
>Run your application.

Now, advanced stuff: change your style at runtime:

I use this button click and formcreate to do this:

Add fdefaultStyleName: String; to your form Private part.

Make sure that Vcl.Themes is in your terms of use.

procedure TForm1.Button1Click(Sender: TObject);
begin
if Assigned(TStyleManager.ActiveStyle) and (TStyleManager.ActiveStyle.Name<>‘Windows’) then begin
TStyleManager.TrySetStyle (‘Windows’);
end else begin
TStyleManager.TrySetStyle(fdefaultStyleName); // whatever was in the project settings.
end;

end;< br />
procedure TForm1.FormCreate(Sender: TObject);
begin
if Assigned(TStyleManager.ActiveStyle) then
fdefaultStyleName := TStyleManager.ActiveStyle.Name;

end;

Is there a good VCL style tutorial, do we see how to load/change styles dynamically (at runtime)?

This should work for Delphi XE2 and later, because XE2 is the first version with VCL style.

< p>I am adding an answer because local information is usually more popular than links.

The following are the key facts you need to know before you start:

>Many VCL Controls have color properties, but when the style is turned on, these properties will be ignored, and the default “common controls” like Button will be drawn by Delphi itself instead of using “or”. With windows”.
>I don’t know. So, deep in your application, the VCL style will introduce some hooks to take over drawing your controls. Everything it can handle will be drawn using the “skin” on top of the regular controls. Many people call it “skinning vcl” Before the VCL style, you may have found a third-party skin system. Now it is built-in.
>Anything without hooks will still get the regular style. So most third-party controls, as well as some bits of VCL None of the topics. Don’t expect perfect instant results. In addition, you may sometimes see some instant flickers or glitches due to skinning, which is to be expected. Add style loading at runtime, and the final quality of the result is anyone A guess. You can’t necessarily guarantee that the style loaded at runtime will contain everything you might want it to contain. You also can’t guarantee to include one statically in your application, but at least the ones you statically include can be made by your The QA team (probably you) verify.

This is the easiest step to start: really only steps #2 to #4 are essential.

>Click on the file –>New –>VCL form project.
>Right click on the project option in the “Project Manager” pane, and then click on “Properties”. Navigate to the application -> appears
>Click Customize Style to open it. (Amakrits is the first in my list, so I will click on it).
>Click the default style combo box and change it to a value other than the default.
>in Put something on the form so that it won’t be empty. (Buttons, list boxes, etc.).
>Run your application.

Now, advanced things: change yours at runtime Style:

I use this button click and formcreate to do this:

Add fdefaultStyleName: String; to the private part of your form.

Make sure Vcl .Themes are in your terms of use.

procedure TForm1.Button1Click(Sender: TObject);
begin< br /> if Assigned(TStyleManager.ActiveStyle) and (TStyleManager.ActiveStyle.Name<>'Windows') then begin
TStyleManager.TrySetStyle('Windows');
end else begin
TStyleManager .TrySetStyle(fdefaultStyleName); // whatever was in the project settings.
end;

end;

procedure TForm1.FormCreate(Sender: TObject);< br />begin
if Assigned(TStyleManager.ActiveStyle) then
fdefaultStyleName := TStyleManager.ActiveStyle.Name;

end;

Leave a Comment

Your email address will not be published.