StyleBook 介紹及VICEN對皮膚控件的一些看法
可以說StyleBook的出現,簡直是皮膚控件廠商的噩夢,因為使用者可以通過StyleBook快速切換控件樣式,而不需要在去購買第三方換膚控件,對于免費并且是官方內建的StyleBook來說,優勢不言而喻。是以,以後的皮膚控件除非有自己的特色,例如Raize,提供了很多系統沒有的控件,并且有自己的獨特的外形風格,否則很難在發展下去。我們很期待有一套類似QQ樣的界面控件套件,可以換膚、切換視窗樣式顔色、跟換視窗背景圖檔等。
先來看看StyleBook為我們提供了哪些預設的界面風格,這些界面風格都被安裝在:
..\Program Files\Embarcadero\RAD Studio\9.0\Redist\styles\Fmx\
目錄下,如果你要釋出你的程式,将這裡的你需要用到的.style檔案一并複制到你釋出軟體目錄即可。
StyleBook提供的界面風格如下:
Windows7.Style
RubyGraphite.style
MacGraphite.Style
MacBlue.Style
IOS.Style
GoldenGraphite.Style
FMX.Platform.Win.style
FMX.Platform.Mac.style
FMX.Platform.iOS.style
dark.style
Blend.Style
AquaGraphite.style
Amakrits.Style
Air.Style
雖然并不多,但可以自行設計擴充,而且支援動态切換,使用也相當的簡單。
下面我們看看如何來使用 StyleBook
1) 首先我們來建立一個FireMonkey HD Application工程
2) 在視窗上放一個StyleBook控件,它位于Standard控件頁下。
3) 将視窗的StyleBook屬性與StyleBookl控件連結。
procedure TFrmStyleTest.FormCreate(Sender: TObject);
begin
Self.StyleBook := StyleBook;
end;
4) 現在就可以使用StyleBook.FileName := ‘樣式名稱’ 來切換樣式了,需要特别注意的是,樣式檔案必須與EXE在同一個目錄,因為測試程式樣式檔案沒加路徑,如果不在同一目錄就沒顯示效果。

unit FireStyle;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Menus, FMX.Edit,
FMX.ListBox, FMX.Layouts, FMX.Memo;
type
TFrmStyleTest = class(TForm)
StyleBook: TStyleBook;
MainMenu: TMainMenu;
Menu_File: TMenuItem;
Menu_File_Open: TMenuItem;
Menu_Help: TMenuItem;
Menu_File_New: TMenuItem;
Menu_File_Line0: TMenuItem;
Menu_File_Quit: TMenuItem;
Menu_Help_About: TMenuItem;
Chk_Test: TCheckBox;
Rb_Style_0: TRadioButton;
Rb_Style_1: TRadioButton;
Rb_Style_2: TRadioButton;
Rb_Style_3: TRadioButton;
Rb_Style_4: TRadioButton;
Rb_Style_5: TRadioButton;
Rb_Style_6: TRadioButton;
Rb_Style_7: TRadioButton;
Rb_Style_8: TRadioButton;
Rb_Style_9: TRadioButton;
Rb_Style_10: TRadioButton;
Rb_Style_11: TRadioButton;
Rb_Style_12: TRadioButton;
Rb_Style_13: TRadioButton;
Lab_StyleName: TLabel;
But_Close: TButton;
Ed_StyleName: TEdit;
tb_Test: TTrackBar;
pb_Bar: TProgressBar;
sb_Test: TScrollBar;
cmb_Test: TComboBox;
ListBoxItem1: TListBoxItem;
ListBoxItem2: TListBoxItem;
ListBoxItem3: TListBoxItem;
Memo_Test: TMemo;
tmr_Process: TTimer;
procedure FormCreate(Sender: TObject);
procedure But_CloseClick(Sender: TObject);
procedure Menu_File_QuitClick(Sender: TObject);
procedure Rb_Style_0Click(Sender: TObject);
procedure tmr_ProcessTimer(Sender: TObject);
private
procedure ApplyStyle(swStyle: WideString);
{ Private declarations }
public
{ Public declarations }
end;
var
FrmStyleTest: TFrmStyleTest;
implementation
{$R *.fmx}
procedure TFrmStyleTest.But_CloseClick(Sender: TObject);
begin
Close;
end;
procedure TFrmStyleTest.FormCreate(Sender: TObject);
begin
Self.StyleBook := StyleBook;
ApplyStyle('iOS.style');
end;
procedure TFrmStyleTest.Menu_File_QuitClick(Sender: TObject);
begin
Close;
end;
procedure TFrmStyleTest.Rb_Style_0Click(Sender: TObject);
begin
try
ApplyStyle((Sender as TRadioButton).Text);
except end;
end;
procedure TFrmStyleTest.tmr_ProcessTimer(Sender: TObject);
begin
if (pb_Bar.Value + 1) > 100 then pb_Bar.Value := 0
else pb_Bar.Value := pb_Bar.Value + 1;
end;
procedure TFrmStyleTest.ApplyStyle(swStyle:WideString);
begin
if swStyle<>'' then StyleBook.FileName := swStyle;
Ed_StyleName.Text := swStyle;
end;
end.