Delphi 4.0换肤
点击次数:59 次 发布日期:2008-11-09 08:37:37 作者:源代码网
|
源代码网推荐 源代码网推荐 现在软件的界面设计很流行“换肤”(SKIN),例如ICQ、Winamp、超级解霸等等。这种技术 源代码网推荐 的应用可以最大程度的彰显用户的个性,所以一经推出就大受欢迎。其实这种技术实现起来很简 源代码网推荐 单,下面就是我用Delphi 4.0换肤的例子。 源代码网推荐 源代码网推荐 首先,在窗体上放一个Image控件,一个Button控件和一个OpenDialog控件。 源代码网推荐 源代码网推荐 然后,修改属性。将窗体的Caption属性改为Test Skin Program;将Image控件的Align 源代码网推荐 属性改为alClient,将Stretch属性改为True;将Button控件的Caption属性改为Skin。其余属性不 源代码网推荐 变。 源代码网推荐 源代码网推荐 最后,输入代码吧! 源代码网推荐 源代码网推荐 unit mainform; 源代码网推荐 源代码网推荐 interface 源代码网推荐 源代码网推荐 uses 源代码网推荐 源代码网推荐 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 源代码网推荐 源代码网推荐 StdCtrls, Buttons, ExtCtrls,inifiles, jpeg, Menus; 源代码网推荐 源代码网推荐 //一定要将inifiles单元加入uses 源代码网推荐 源代码网推荐 type 源代码网推荐 源代码网推荐 TForm1 = class(TForm) 源代码网推荐 源代码网推荐 Image1: TImage; 源代码网推荐 源代码网推荐 OpenDialog1: TOpenDialog; 源代码网推荐 源代码网推荐 Button1: TButton; 源代码网推荐 源代码网推荐 procedure FormCreate(Sender: TObject); 源代码网推荐 源代码网推荐 procedure Button1Click(Sender: TObject); 源代码网推荐 源代码网推荐 private 源代码网推荐 源代码网推荐 { Private declarations } 源代码网推荐 源代码网推荐 public 源代码网推荐 源代码网推荐 { Public declarations } 源代码网推荐 源代码网推荐 end; 源代码网推荐 源代码网推荐 var 源代码网推荐 源代码网推荐 Form1: TForm1; 源代码网推荐 源代码网推荐 implementation 源代码网推荐 源代码网推荐 {$R*.DFM} 源代码网推荐 源代码网推荐 procedure TForm1.FormCreate(Sender: TObject); 源代码网推荐 源代码网推荐 Var 源代码网推荐 源代码网推荐 SkinINI : Tinifile; 源代码网推荐 源代码网推荐 SkinPicture : String; 源代码网推荐 源代码网推荐 begin 源代码网推荐 源代码网推荐 SkinINI := TiniFile.Create("c:my documentsskin.ini"); 源代码网推荐 源代码网推荐 SkinPicture:=SkinINI.ReadString("Interface","skin",""); 源代码网推荐 源代码网推荐 //将“皮肤”的图片信息存储在SKIN.INI文件中。当然,你还可以将更多的信息存进该文件中。 源代码网推荐 源代码网推荐 //例如:SKIN.INI 源代码网推荐 源代码网推荐 //[interface] 源代码网推荐 源代码网推荐 // skin = c:my documentsmylove.jpg 源代码网推荐 源代码网推荐 IF SkinPicture<>"" then 源代码网推荐 源代码网推荐 Begin 源代码网推荐 源代码网推荐 try 源代码网推荐 源代码网推荐 Image1.Picture.LoadFromFile(SkinPicture); 源代码网推荐 源代码网推荐 except 源代码网推荐 源代码网推荐 end; 源代码网推荐 源代码网推荐 End; 源代码网推荐 源代码网推荐 SkinINI.Free; 源代码网推荐 源代码网推荐 end; 源代码网推荐 源代码网推荐 procedure TForm1.Button1Click(Sender: TObject); 源代码网推荐 源代码网推荐 Var 源代码网推荐 源代码网推荐 SkinINI : Tinifile; 源代码网推荐 源代码网推荐 SkinPicture : String; 源代码网推荐 源代码网推荐 Success : Boolean; //指示换肤是否成功 源代码网推荐 源代码网推荐 begin 源代码网推荐 源代码网推荐 SkinINI := TiniFile.Create("c:my documentsskin.ini"); 源代码网推荐 源代码网推荐 SkinPicture:=SkinINI.ReadString("Interface","skin",""); 源代码网推荐 源代码网推荐 OpenDialog1.Filter:="All Image File(*.jpg;*.jpeg;*.bmp;*.ico)|*.jpg;*.jpeg;*.bmp;*.ico|"+ 源代码网推荐 源代码网推荐 "Bitmaps(*.bmp)|*.bmp|"+ 源代码网推荐 源代码网推荐 "Jpeg Image File(*.jpg;*.jpeg)|*.jpeg;*.jpg|"+ 源代码网推荐 源代码网推荐 "Icons(*.ico)|*.ico"; 源代码网推荐 源代码网推荐 Success:=True; 源代码网推荐 源代码网推荐 IF OpenDialog1.Execute then 源代码网推荐 源代码网推荐 Begin 源代码网推荐 源代码网推荐 try 源代码网推荐 源代码网推荐 Image1.Picture.LoadFromFile(OpenDialog1.Filename); 源代码网推荐 源代码网推荐 except 源代码网推荐 源代码网推荐 Application.MessageBox("This file is not load!","Error!",MB_OK); 源代码网推荐 源代码网推荐 Success:=False; 源代码网推荐 源代码网推荐 end; 源代码网推荐 源代码网推荐 IF Success then SkinINI.WriteString("interface","skin",OpenDialog1.Filename); 源代码网推荐 源代码网推荐 //若换肤成功,将图片信息存进skin.ini文件中 源代码网推荐 源代码网推荐 End; 源代码网推荐 源代码网推荐 SkinINI.Free; 源代码网推荐 源代码网推荐 end; 源代码网推荐 源代码网推荐 end. 源代码网推荐 源代码网推荐 怎么样,换肤简单吧(什么东西都是“难的不会,会的不难”)!你还可以在此基础上继续向窗 源代码网推荐 体上添加各种控件。因为这只是一个示例,所以就没有加那些。另外,严格得说,“换肤”指令应该 源代码网推荐 在菜单中(即MainMenu控件中,其实也很简单)。但为了没有“赚稿酬”之嫌,所以就用一个Button 源代码网推荐 应付了。 源代码网推荐 源代码网供稿. |
