好久没来了,请问各位大虾一个问题!!!(30分)

  • 主题发起人 主题发起人 fxh7622
  • 开始时间 开始时间
F

fxh7622

Unregistered / Unconfirmed
GUEST, unregistred user!
我设计了一个原角的按钮,现在我想让当鼠标移动到按钮时背景色进行渐变变化。
 
不知道這些對你有否幫助

unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
Timer2: TTimer;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure WMNCHITTEST(var Msg: TWMNCHITTEST); message WM_NCHITTEST;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
procedure TForm1.WMNCHITTEST(var Msg: TWMNCHITTEST);
begin
inherited;
if Msg.Result = HTCAPTION then
Msg.Result := 0
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Canvas.Font.Name := 'Times New Roman';
Canvas.Font.size := 36;
Canvas.Font.style := [fsItalic,fsBold];
Canvas.Pen.Color := clGreen;
SetBkMode( Canvas.Handle, TRANSPARENT );
Canvas.TextOut(20,40,'I love delphi');
beginpath(canvas.handle);
Canvas.TextOut(20,40,'I love delphi');
endpath(canvas.handle);
Canvas.Pen.Color := clred;
StrokePath(canvas.handle);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
S,SS :String;
Len,i :Integer;
begin
S :='I love delphi';
SS :='';
Len :=Length(S);
Canvas.Font.Name := 'Times New Roman';
Canvas.Font.size := 36;
Canvas.Font.style := [fsItalic,fsBold];
Canvas.Font.Color :=RGB(Random(255),Random(255),Random(255));
for i:=1 to Len do
begin
SetBkMode( Canvas.Handle, TRANSPARENT );
Canvas.TextOut(20,40,SS+S);
SS :=SS+S;
Sleep(100);
end;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
var
Bmp :TBitmap;
S :String;
i :Integer;
begin
S :='¨÷°_¤d°ï³·';
Bmp :=TBitmap.Create;
Bmp.Width :=Width;
Bmp.Height :=Form1.Height;
Bmp.Canvas.Brush.Color :=clBtnFace;
Bmp.Canvas.Rectangle(0,0,Bmp.Width,Bmp.Height);
SetBKMode(Bmp.Canvas.Handle,TRANSPARENT);
Bmp.Canvas.Font.Size :=72;
Bmp.Canvas.Font.Color :=RGB(Random(255),Random(255),Random(255));
Bmp.Canvas.TextOut(0,0,S);
for i :=0 to Bmp.Width-1 do
Canvas.CopyRect(Rect(0,0,i,Bmp.Height),Bmp.Canvas,Rect(0,0,i,Bmp.Height));
Bmp.Free;
end;
 
CM_MOUSEENTER// 鼠标进入
CM_MOUSELEAVE//鼠标退出
呵呵。。。得到鼠标是否进入退出后。。带一个TTIMER。进入就激发TIMER。变换着画。
懂了吗???就是这两个消息搞盯


这30分我要了。看框架代码:
TYouBtn=Class(TCustomControl);
private
FTimer:TTimer;
procedure CMMOUSEENTER(var Msg:TMessage);mesage CM_MOUSEENTER;
.............................
constructor TYouBtn.Create(AOwner:TComponent);
begin
FTimer:=TTimer.Create(Self);
FTImer.Enabled:=false;
end;
procedure TYouBtn.CMMOUSEENTER(var Msg:TMessage);
begin
FTimer.Enabled:=true;
end;
//处理鼠标离开后的代码里。恢复BTN的外观。且停止TIMER;
//在你的FTimer.Time事件里。画你的吧。想怎么变怎么变。别望了。画出来要刷新哦 。呵呵。。。。
//最后。。DESTROY 掉你的 FTIMER
 
后退
顶部