可以讲一下如何用Microsoft Visual FoxPro 6.0制作一个五一节的倒计时程序和需要表单的详细步骤吗?

2025-05-20 10:04:03
推荐回答(1个)
回答1:

设计的表单和相关代码:

1)设计的表单

2)运行时的效果

3)相关代码:

(1)表单的init事件

         thisform.Caption = "倒计时"         &&窗体标题

         thisform.label3.Caption = ""        &&当前计数值

         thisform.label3.FontBold = .T.      &&计数值加粗

         thisform.label3.FontSize = 48       &&计数值字体大小

         thisform.text1.InputMask = "99999"  &&设置文本框的只能输入数字

         thisform.command2.Enabled = .F.     &&屏蔽“暂停”按钮

         thisform.timer1.Interval = 0        &&取消定时器

         PUBLIC oper as Boolean 

         oper = .F.

(2)“开始”按钮的单击click事件

         n = VAL(ALLTRIM(thisform.label3.Caption))     &&当前计数值

         IF oper = .F. THEN   &&第一次按“开始”按钮

                  n = VAL(ALLTRIM(thisform.text1.Value))    &&取得计数的初值

         ENDIF 

         IF n>0 THEN   

                  thisform.label3.Caption = ALLTRIM(STR(INT(n)))  &&显示计数的初值

                  thisform.timer1.Interval = 1000   &&打开定时器

                  this.Enabled = .F.                &&屏蔽“开始”按钮

                  thisform.command2.Enabled = .T.   &&打开“暂停”按钮

                  thisform.text1.ReadOnly = .T.     &&文本框只读

                  oper = .T. 

         ELSE 

                  MESSAGEBOX("计数值未输入或错误!",0+48,"提示")

                  thisform.text1.SetFocus 

         ENDIF 

(3)“暂停”按钮的单击click事件

         thisform.timer1.Interval = 0    &&取消定时器

         this.Enabled = .F.              &&屏蔽“暂停”按钮

         thisform.command1.Enabled = .T. &&打开“开始”按钮

(4)“重置”按钮的单击click事件 

         thisform.text1.Value = ""     &&清空文本框

         thisform.label3.Caption = ""  &&清空计数值

         thisform.timer1.Interval = 0  &&结束计数

         thisform.command1.Enabled = .T. &&打开“开始”按钮

         thisform.command2.Enabled = .F. &&屏蔽“暂停”按钮

         thisform.text1.ReadOnly = .F.   &&取消文本框只读

         oper = .F.

(5)定时器的Timer事件

         n = VAL(ALLTRIM(thisform.label3.Caption))    &&取得当前计数值

         n = n-1

         IF n=0 THEN 

                  thisform.timer1.Interval = 0  &&结束计数

                  thisform.command1.Enabled = .T. 

                  thisform.command2.Enabled = .F. 

                  oper = .F.

         ENDIF 

         thisform.label3.Caption = ALLTRIM(STR(INT(n)))

         thisform.Refresh