|
以下的代码,在不用换肤控件的情况下,轻松实现换肤的功能:
- unit Unit1;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Buttons,
- ExtCtrls;
- type
- { TForm1 }
- TForm1 = class(TForm)
- BitBtn1: TBitBtn;
- BitBtn2: TBitBtn;
- Image1: TImage;
- Image2: TImage;
- SpeedButton1: TSpeedButton;
- SpeedButton2: TSpeedButton;
- SpeedButton3: TSpeedButton;
- procedure BitBtn1Click(Sender: TObject);
- procedure BitBtn2Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormPaint(Sender: TObject);
- procedure SpeedButton3Click(Sender: TObject);
- private
- { private declarations }
- public
- { public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.lfm}
- { TForm1 }
- var
- tc1,tc2:Trect;
- which_color:byte;
- which_status:byte;
- color_show:array [1..2,1..2] of Tcolor
- =(
- (cllime,clyellow),
- (claqua,clbtnface)
- );
- procedure TForm1.FormPaint(Sender: TObject);
- begin
- case which_status of
- 1:
- begin
- tc1.Left:=0;
- tc1.Right:=self.Width;
- tc1.Top:=0;
- tc1.Bottom:=25;
- tc2.Top:=tc1.Bottom;
- tc2.Right:=tc1.Right;
- tc2.Left:=tc1.Left;
- tc2.Bottom:=self.Height;
- with self.Canvas do
- begin
- Brush.Color:=color_show[which_color][1];
- FillRect(tc1);
- Brush.Color:=color_show[which_color][2];
- FillRect(tc2);
- end;
- end;
- 2:
- begin
- case which_color of
- 1:
- begin
- image1.Visible:=true;
- image2.Visible:=false;
- end;
- 2:
- begin
- image1.Visible:=false;
- image2.Visible:=true;
- end;
- end;
- end;
- end;
- end;
- procedure TForm1.SpeedButton3Click(Sender: TObject);
- begin
- close;
- end;
- procedure TForm1.BitBtn1Click(Sender: TObject);
- begin
- image1.Visible:=false;
- image2.Visible:=false;
- which_status:=1;
- if (which_color=1) then which_color:=2
- else which_color:=1;
- refresh;
- end;
- procedure TForm1.BitBtn2Click(Sender: TObject);
- begin
- which_status:=2;
- if (which_color=1) then which_color:=2
- else which_color:=1;
- refresh;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- self.BorderStyle:=bsnone;
- end;
- end.
复制代码
效果图:
|
评分
-
查看全部评分
|