Delphi 定时器之Timer1【淡出淡进效果】

RAD Studio 10.4 测试√


1、Timer的主要属性

属性属性解释
Enabled当值为True时,打开定时器,否则关闭定时器。默认值为true。
Interval控制OnTimer事件触发的时间间隔,单位是毫秒。将Interval设置为0,相当于关闭定时器。默认值为1000ms(1秒)。

2、Timer的主要事件
Timer只有一个OnTimer事件。当Timer打开时,每经过Interval属性指定的时间,Timer就会触发OnTimer事件,执行其中的程序。


控件:Timer、scGPGlyphButton
代码大概的意思就是通过定时器的 Interval 来搞事情,设置scGPGlyphButton 获取焦点、鼠标移上去和失去焦点时的颜色的不透明度,达到淡出淡进的效果。

//全局变量int1,state1
var
  int1: Integer = 0;
  state1: String = '停止';
  
***************************************************************

procedure TMainF.scGPGlyphButton1MouseEnter(Sender: TObject); // 鼠标进入事件
begin
  int1 := 0;
  state1 := '开始';
end;

procedure TMainF.scGPGlyphButton1MouseLeave(Sender: TObject); // 鼠标离开事件
begin
  state1 := '停止';
end;

procedure TMainF.Timer1Timer(Sender: TObject);
var
  i: Integer;
begin
  i := int1;
  if state1 = '开始' then
  begin
    if ((0 <= i) and (i < 255)) then
    begin
      MainF.scGPGlyphButton1.Options.HotColorAlpha := i;
      i := i + 1;
      Memo1.Lines.Add(IntToStr(i));
      int1 := i;
    end;
  end
  else if state1 = '停止' then
  begin
    if ((0 < i) and (i <= 255)) then
    begin
      i := i - 1;
      MainF.scGPGlyphButton1.Options.NormalColorAlpha := i;
      MainF.scGPGlyphButton1.Options.FocusedColorAlpha := i;
      Memo1.Lines.Add(IntToStr(i) + '减去');
      int1 := i;
    end;
  end;
end;

学习中记录的一点点笔记,以便以后翻阅。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小印丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值