不好意思我忘记在你的鼠标离开是恢复label1的颜色 这样 在label1的onmousemove加入 label1.font.color:=blue; 然后在你的from1的onmousemove加入 label1.Font.Color:=clWindowText; 就可以了 但你不知道你的label1是不是直接放在了窗体上如果不是就在你放置的控健的onmousemove加入 label1.Font.Color:=clWindowText; 但是要考虑到资源的占用问题 可以在后者的加入 if label1.font.color<>clwindowtext then label1.Font.Color:=clWindowText;
//The Label1 become blue When mouse enter //and become black when mouse leave procedure cmMouseEnter(var msg: TMessage); message CM_MOUSEENTER; procedure cmMouseLeave(var msg: TMessage); message CM_MOUSELEAVE;procedure TForm1.cmMouseEnter(var msg: TMessage); begin if (msg.LParam=integer(Label1)) and (Label1.Font.Color<>clBlue) then Label1.Font.Color:=clBlue; end;procedure TForm1.cmMouseLeave(var msg: TMessage); begin if (msg.LParam=integer(Label1)) and (Label1.Font.Color=clBlue) then Label1.Font.Color:=clBlack; end;
就可以了,如果要实现简单的鼠标移开后恢复原先的字体设置,也可以用其它部件(多数是
Form、Panel)的OnMOuseMove实现。
根本解决方法是:用消息映射实现 MouseHover、MouseLeave功能。
label1.font.Size:=16;
label1.font.Color:=clyellow;
在form1中的onMouseMove中恢复以上的设置.
或者你通过一个系统的变量来控制以上的设置
代码
label1.font.color:=1002;
看看有何变化
这样
在label1的onmousemove加入
label1.font.color:=blue;
然后在你的from1的onmousemove加入
label1.Font.Color:=clWindowText;
就可以了
但你不知道你的label1是不是直接放在了窗体上如果不是就在你放置的控健的onmousemove加入
label1.Font.Color:=clWindowText;
但是要考虑到资源的占用问题
可以在后者的加入
if label1.font.color<>clwindowtext then
label1.Font.Color:=clWindowText;
//and become black when mouse leave procedure cmMouseEnter(var msg: TMessage); message CM_MOUSEENTER;
procedure cmMouseLeave(var msg: TMessage); message CM_MOUSELEAVE;procedure TForm1.cmMouseEnter(var msg: TMessage);
begin
if (msg.LParam=integer(Label1)) and (Label1.Font.Color<>clBlue) then
Label1.Font.Color:=clBlue;
end;procedure TForm1.cmMouseLeave(var msg: TMessage);
begin
if (msg.LParam=integer(Label1)) and (Label1.Font.Color=clBlue) then
Label1.Font.Color:=clBlack;
end;
你可以用两个Tlabel,吧他们重合放在一起(稍微有点偏).设置他们的color的属性,其他的属性一样.
procedure wmmouseleave(msg:message); message wm_mouseleave;