最前面的話:Smobiler是一個在VS環境中使用.Net語言來開發APP的開發平台,也許比Xamarin更方便
我們要實現上圖中的效果,需要如下的操作:
VB: Private Sub timer1_Tick(sender As Object, e As EventArgs) Handles timer1.Tick Me.TextBox1.Text = (Convert.ToInt32(Me.textBox1.Text.ToString()) - 1).ToString() End Sub
C#: private void timer1_Tick(object sender, EventArgs e) { this.textBox1.Text =(Convert.ToInt32(this.textBox1.Text.ToString()) -1).ToString(); }
注:調用Timer控件
VB: Private Sub textBox1_TextChanged(sender As Object, e As EventArgs) Handles textBox1.TextChanged If Me.textBox1.Text = "0" Then timer1.Stop() Else timer1.Start() End If End Sub
C#: private void textBox1_TextChanged(object sender, EventArgs e) { if(this.textBox1.Text =="0") { timer1.Stop(); } else { timer1.Start(); } }
注:判斷條件來選擇開始定時器還是停止定時器
VB: Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click Me.textBox1.Text = "60" End Sub
C#: private void button1_Click(object sender, EventArgs e) { this.textBox1.Text ="60"; }
觸發Tick事件的間隔時間,以秒為單位,默認設置為“1”,即間隔時間為1秒,見下圖;