【AHK V2】 定时刷新窗口中的控件内容

在AutoHotkey v2 中设计GUI窗口,窗口中有个文本框,可以定时刷新内容。 时间周期可以通过窗口中的 下拉框来设定。

/************************************************************************
 * @description 
 * @file 控件自动更新.ahk
 * @author sunwind1576157
 * @date 2024/07/02
 * @version 0.0.1
 ***********************************************************************/

myGui := Gui()
myGui.Add("Text",, "请选择更新周期:")
myCmb:=myGui.AddComboBox("vPeriodChoice ", ["1","5","10"])
myEdt:=myGui.AddEdit("vTimer")
myGui.Show()
myCmb.OnEvent("Change", setConunter)
setConunter(*)
{
    counter := SecondCounter(myCmb.Text)
    counter.Start
    myEdt.Value:="第0次运行,"  FormatTime("T12", "Time")
}

class SecondCounter {
    __New(秒数:=1) {
        this.interval := 1000*秒数
        this.count := 0
        ; Tick() 有一个隐式参数 "this", 其引用一个对象
        ; 所以, 我们需要创建一个封装了 "this " 和调用方法的函数:
        this.timer := ObjBindMethod(this, "Tick")
    }
    Start() {
        SetTimer this.timer, this.interval
        ToolTip "Counter started"
    }
    Stop() {
        ; 要关闭计时器, 我们必须传递和之前一样的对象:
        SetTimer this.timer, 0
        ToolTip "Counter stopped at " this.count
    }
    Tick() {
        ++this.count
        myEdt.Value:="第" this.count "次运行,"  FormatTime("T12", "Time")
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

liuyukuan

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

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

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

打赏作者

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

抵扣说明:

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

余额充值