It's cool that Delphi XE3 and below have styles for our applications. But I've noticed that we can mark as many styles as we want and them choose which of them to use as default.
It means that we could change styles at will, but how to do it in code? And how to let the user choose which style to use in our software?
TStyleManager
does what you need to accomplish this task. Use TStyleManager.StyleNames
to get a list of the styles, and TStyleManager.TrySetStyle
to change them at runtime.
To see how this works, start a new VCL Forms Application
. Add all of the VCL styles you want to the project, and drop a TComboBox
on a form. You'll need to add the implementation
uses
clause like I have below:
uses
Vcl.Themes;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
TStyleManager.TrySetStyle(ComboBox1.Items[ComboBox1.ItemIndex]);
end;
procedure TForm1.FormShow(Sender: TObject);
var
s: String;
begin
ComboBox1.Items.BeginUpdate;
try
ComboBox1.Items.Clear;
for s in TStyleManager.StyleNames do
ComboBox1.Items.Add(s);
ComboBox1.Sorted := True;
// Select the style that's currently in use in the combobox
ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(TStyleManager.ActiveStyle.Name);
finally
ComboBox1.Items.EndUpdate;
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With