點擊啟動按鈕時文本框內容自動顯示100次,到了100次立即清零重新開始,如果選中復選框按鈕,則進度條進度會跟隨文本框的內容變。
點擊重做按鈕時,所有的都停止。代碼如下:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.MaxLength = 100 '文本框最大長度為100 TextBox1.ReadOnly = True '文本框在運行時只讀,不可寫入 TextBox1.Multiline = True '文本框內容可在多行顯示 Timer1.Interval = 10 '間隔10ms顯示“8” ' Me.AcceptButton = Button1 '按鍵盤上回車鍵同點擊Button1 按鈕有相同的效果 ' Me.CancelButton = Button2 ‘按鍵盤上esc鍵同點擊Button2 按鈕效果相同 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False Timer1.Enabled = True End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Enabled = False Button1.Enabled = True TextBox1.Text = "" Label1.Text = "當期字符數(shù)=" & TextBox1.Text CheckBox1.Checked = False ProgressBar1.Value = 0 End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
TextBox1.Text = TextBox1.Text & "8" Label1.Text = "當前字符數(shù)=" & TextBox1.TextLength '標簽內容動態(tài)顯示文本框長度 If TextBox1.TextLength = TextBox1.MaxLength Then '如果文本框長度等于最大長度則文本框清零重新計數(shù) TextBox1.Text = "" End If If CheckBox1.Checked = True Then ProgressBar1.Value = TextBox1.TextLength '如果選中了復選框,進度條跟隨文本框長度一起變化 End If End Sub End Class |
|