找回密码
 加入
搜索
查看: 1355|回复: 5

倒计时程序,如何使秒小于10后,还显示两位数呢?

[复制链接]
发表于 2009-7-30 16:53:42 | 显示全部楼层 |阅读模式
本帖最后由 ziyaxian 于 2009-7-30 17:46 编辑

请看下面的程序,当秒小于10后,只显示一位数了,我想当秒小于10时还显示两位数,比如:9时显示09,0时显示00,程序刚运行时显示5:00
#include <GUIConstantsEx.au3>
 
$Form = GUICreate("5分钟倒计时", 280, 230, 195, 125)
GUISetState(@SW_SHOW)
 

Global $sec = 0
Global $min = 5
#Region ### START Koda GUI section ### Form=
$Label5 = GUICtrlCreateLabel($sec , 125, 50, 200,80)
GUICtrlSetFont(-1, 72, 400, 0, "楷体_GB2312")
$Label6 = GUICtrlCreateLabel($min & ":",55,50,70,80)
GUICtrlSetFont(-1, 72, 400, 0, "楷体_GB2312")
$Button1 = GUICtrlCreateButton("开始", 50, 180, 73, 25, 0)
$Button2 = GUICtrlCreateButton("重新开始", 150, 180, 73, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
        $nMsg = GUIGetMsg()
                Switch $nMsg
                Case -3
                    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Form, "int", 500, "long", 0x00090000)
                    Exit
                                Case $Button1
                                    AdlibEnable("_timer", 1000)
                Case $Button2
                    AdlibDisable()
                    $sec = 0
                    $min = 5                                                
                        GUICtrlSetData($Label5,$sec)
                            GUICtrlSetData($Label6,$min &":")        
        EndSwitch
WEnd

Func _timer()
        If $sec <= 0 Then 
                $sec = 60+$sec
                $min -= 1
                EndIf
        $sec -= 1
        GUICtrlSetData($Label5,$sec)
                GUICtrlSetData($Label6,$min &":")
                
EndFunc 
 楼主| 发表于 2009-7-30 17:15:32 | 显示全部楼层


再发个图片,上面的5:0 能否显示成 05:00呢?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2009-7-30 17:25:39 | 显示全部楼层
本帖最后由 afan 于 2009-7-30 18:19 编辑
#include <GUIConstantsEx.au3>

$Form = GUICreate("5分钟倒计时", 280, 230, 195, 125)
GUISetState(@SW_SHOW)

Global $sec = 0
Global $min = 5

$Label5 = GUICtrlCreateLabel(StringFormat('%02s', $sec), 145, 50, 90, 80)
GUICtrlSetFont(-1, 72, 400, 0, "楷体_GB2312")
$Label6 = GUICtrlCreateLabel(StringFormat('%02s', $min) & ":", 30, 50, 120, 80)
GUICtrlSetFont(-1, 72, 400, 0, "楷体_GB2312")
$Button1 = GUICtrlCreateButton("开始", 50, 180, 73, 25, 0)
$Button2 = GUICtrlCreateButton("重新开始", 150, 180, 73, 25, 0)
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case - 3
                        DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Form, "int", 500, "long", 0x00090000)
                        Exit
                Case $Button1
                        AdlibEnable("_timer", 1000)

                Case $Button2
                        AdlibDisable()
                        $sec = 0
                        $min = 5
                        GUICtrlSetData($Label5, StringFormat('%02s', $sec))
                        GUICtrlSetData($Label6, StringFormat('%02s', $min) & ":")
        EndSwitch
WEnd

Func _timer()
        If $sec = 0 And $min = 0 then
                AdlibDisable()
        Else
                If $sec <= 0 Then
                        $sec = 60 + $sec
                        $min -= 1
                EndIf
                $sec -= 1
                GUICtrlSetData($Label5, StringFormat('%02s', $sec))
                GUICtrlSetData($Label6, StringFormat('%02s', $min) & ":")
        Endif
EndFunc   ;==>_timer
 楼主| 发表于 2009-7-30 17:45:47 | 显示全部楼层
谢谢,正是我想要的,再次感谢
发表于 2009-7-30 18:00:34 | 显示全部楼层
本帖最后由 afan 于 2009-7-30 19:24 编辑

顺便改了一下,到00:00 即停止,不再计时。
发表于 2009-7-30 19:59:10 | 显示全部楼层
AdlibEnable改为Adlibregister,dlibDisable改为dlibunregister--新版本
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-2 17:10 , Processed in 0.070340 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表