首页 文章

使用Vbscript图形元素显示倒计时的VBScript

提问于
浏览
0

我想显示一个MessageBox,它显示从10到1的倒计时,并在10秒后自动关闭 . 由于vbscript中的Msgbox传递代码执行,直到用户对其进行操作,我在Wscript Shell对象中使用Popup尝试了它

Dim counter
Dim oShell
counter = 10
Set oShell= CreateObject("Wscript.Shell")
While counter > 0

oShell.Popup " Left " & counter & " Seconds",1,"Remind"
counter = counter-1
Wend

但它每秒自动关闭并打开一个新的弹出窗口有什么方法我可以使用vb脚本中的可用GUI元素显示倒计时和自动关闭

2 回答

  • 1

    不敢这样,弹出窗口是模态的,并且在显示时无法与之交互,因此无法更新其现有内容 .

    如果您想要更灵活的UI,则需要在HTA中使用不同的控制台或HTML .

  • 1

    您可以使用Internet Explorer创建非模态显示 .

    Set oIE = CreateObject("InternetExplorer.Application")
    
    With oIE
        .navigate("about:blank")
        .Document.Title = "Countdown" & string(100, chrb(160))
        .resizable=0
        .height=200
        .width=100
        .menubar=0
        .toolbar=0
        .statusBar=0
        .visible=1
    End With
    
    ' wait for page to load
    Do while oIE.Busy
        wscript.sleep 500
    Loop
    
    ' prepare document body
    oIE.document.body.innerHTML = "<div id=""countdown"" style=""font: 36pt sans-serif;text-align:center;""></div>"
    
    ' display the countdown
    for i=10 to 0 step -1
        oIE.document.all.countdown.innerText= i
        wscript.sleep 1000
    next
    oIE.quit
    

相关问题