>能实现当mouse 不在该区域时把字再变回去
代码如下:
unit testu;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, StdCtrls;
type
TForm1 = class(TForm)
SpeedButton1: TSpeedButton;
procedure SpeedButton1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMyLabel=class(Tlabel)
procedure CMMouseEnter(var Message: TMessage);
message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage);
message CM_MOUSELEAVE;
end;
var
Form1: TForm1;
implementation
var
ml:TMylabel=nil;
min:boolean=false;
{$R *.DFM}
procedure TMyLabel.CMMouseEnter(var Message: TMessage);
begin
inherited;
if not min then
begin
font.Style :=font.style+[fsUnderline];
min:=true;
Repaint;
end;
end;
procedure TMyLabel.CMMouseLeave(var Message: TMessage);
begin
inherited;
if min then
begin
font.Style :=font.style-[fsUnderline];
min:=false;
Invalidate;
end;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if ml<>nil then
exit;
ml:=tmylabel.Create(self);
ml.parent:=form1;
ml.left:=50;
ml.top:=50;
ml.width:=50;
ml.height:=50;
ml.caption:='abcdefghijklmnopqrstuvwxyz';
ml.show;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if ml<>nil then
ml.free;
end;
end.
>对了,最好还能让mouse在次区域时字突起,不在时恢复原样
修改TMyLabel.CMMouseEnter为:
procedure TMyLabel.CMMouseEnter(var Message: TMessage);
var
PaintRect: TRect;
begin
inherited;
if not min then
begin
// font.Style :=font.style+[fsUnderline];
PaintRect := Rect(0, 0, Width, Height);
DrawEdge(Canvas.Handle, PaintRect, BDR_RAISEDINNER,
BF_RECT);
min:=true;
// Repaint;
end;
end;
试一试吧!