VclSkin使用教程
不像其它控件那样,你需要修改源代码才能构建一个漂亮的界面, VCLskin 能让Delphi的标准控件在一下子就变得非常漂亮,而这一切都不用修改源代码。
- Delphi Form
- MDIform . (normal,Maximized, MInimized)
- Common Windows dialogs (Open/Save,Font,Print,Color).
- MsgBox.
- Exception MsgBox.
- The title bar of TForm
- The title bar buttons
- The borders of Tform
- Tbutton,TBitbtn.
- Tradiobutton and Tcheckbox
- Tmainmenu and Tpopupmenu
- Toolbar buttons
- TTabcontrol and TPageControl
- T Progressbar
- TStatusbar
- TCustomCombox,Tcombobox, TDbCombobox
- TPanel and TGroupbox
- TMemo, TListBox,TListView,TTreeview
- TRadioGroup , TDBRadioGroup.
- TCustomGrid,TStringgrid,TDrawgrid,Tdbgrid.
- Third party component, Enlib, AdvGrid ..
- 解压缩 Vclskin5.4.zip 到任意目录
- 在 Delphi IDE 环境中选择菜单 "File. Open...", 然后找到连接库 vclskindX.dpk, 按着点击Compile(编译)-Install(安装)按钮。
- 在Tool(工具)- Environment (编译环境)-Library-Library path 添加 VCLSkin 控件所在的路径(X:\...\VclSkin5.4\source) 。
DX - Delphi X, X - version CBX - CBuilder X, X - version
(control.tag mod 100=disabletag)
LoadFromFile(value:string);
LoadFromCollection(astore:TSkinStore;aindex:integer);
UpdateMenu(fParent:Tform);
| control:=Tmycontrol.create(form1); skindata1.UpdateSkincontrol(form1); // add this line to skin dynamic control. |
|
procedure TDockableForm.FormShow(Sender: TObject);
begin if MainForm.skindata1.active then MainForm.skindata1.skinform(handle); end; |
| popup:=Tpopupmenu.create(form1); ..... add menuite skindata1.UpdateMenu(form1); //add this line popup.popup(x,y); |
| procedure Tform1.SkinData1FormSkin(Sender: TObject; aName: String; var DoSkin: Boolean); begin //'TppPrintPreview' 就是要取消美化的窗体名称。 if aName='TppPrintPreview' then doskin:=false; end; |
比如说 , 窗体的背景色是 : skindata.Colors[csButtonFace].
|
TShemeColor=(csText,csTitleTextActive,csTitleTextNoActive,
csButtonFace,csButtonText, csButtonHilight,csButtonlight,csButtonShadow,csButtonDkshadow, csSelectText,csSelectBg,csHilightText,csHilight, csMenuBar,csMenuBarText,csMenuText,csMenubg, csScrollbar,csTextDisable); TShemeColors=array[csText..csTextDisable] of Tcolor;
Skindata.Colors: TShemeColors;
|
范例:
先建立一个新工程,加入一些常见的组件。运行结果的界面如图9.18所示。
然后加入一个SkinData控件,把Active属性设为True。再单击SkinStore属性的带省略号的按钮,选择VCLSkin自带的一个皮肤文件macos.skn。然后,编译,运行,结果如图9.19所示。


图9.18 原始程序 图9.19 加入VCLSkin组件后的效果

此处将程序界面从原来古板的样貌变成Mac Os风格没有用一行代码,只设了SkinData的属性。下面我们结合SkinStore组件讲讲程序中“换肤”的做法。
在窗体上加入一个SkinStore组件,在Object Inspector中单击Store后面的带省略号的按钮,出现如图9.20所示的窗体。
单击
图标,新生成一个SkinStore,可以像上面设置SkinData的SkinStore那样设置好它的属性。创建多个SkinStore,存入多个皮肤。然后在窗体的按钮上加入如下代码(代码的作用是当程序运行中按下Button1时,SkinData1会从SkinStore1中读取第1个皮肤,并显示出来):
procedure TForm1.Button1Click(Sender: TObject);
begin
SkinData1.LoadFromCollection(SkinStore1,1);
end;
类似地,加入以下代码:
procedure TForm1.Button3Click(Sender: TObject);
begin
SkinData1.LoadFromCollection(SkinStore1,2);
end;
procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
SkinData1.LoadFromCollection(SkinStore1,3);
end;
“换肤”功能完成了。在程序中按下那几个按钮,程序界面的风格就会相应改变。图9.21示出了两个例子。


图9.21 VCLSkin的另两种皮肤效果
VCLSkin的功能远不止如此,我们挑几个说一下:
· DataSkin有个DisableTag属性。默认值是99。如果窗体上哪个组件的Tag值是99的话,DataSkin不会对这个组件起作用。
· 支持MDI窗体。
· 支持通用Windows对话框(打开,保存文件等)。
· SkinControls属性可以设置对哪类控件起作用。
· 在一个程序中不同窗体可以有不同皮肤风格

浙公网安备 33010602011771号