
![]() 图一、创建一个新的窗体应用程序 |
| Function ComputeFibonacci(ByVal n As Integer) As Long ’ The parameter n must be >= 0 and <= 91. ’ Fib(n), with n > 91, overflows a long. If n < 0 OrElse n > 91 Then Throw New ArgumentException( "value must be >= 0 and <= 91", "n") End If Dim result As Long = 0 If n < 2 Then result = 1 Else result = ComputeFibonacci(n - 1) + ComputeFibonacci(n - 2) End If ’ Report progress as a percentage of the total task. Dim percentComplete As Integer = CSng(n) / CSng(numberToCompute) * 100 If percentComplete > highestPercentageReached Then highestPercentageReached = percentComplete Me.ProgressBar1.Value = percentComplete End If Return result End Function |
| Private Sub startSyncButton_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles startSyncButton.Click ’ Reset the text in the result label. result.Text = [String].Empty ’ Disable the UpDown control until ’ the synchronous operation is done. Me.numericUpDown1.Enabled = False ’ Disable the Start button until ’ the synchronous operation is done. Me.startSyncButton.Enabled = False ’ Enable the Cancel button while ’ the synchronous operation runs. Me.cancelSyncButton.Enabled = True ’ Get the value from the UpDown control and store it ’ in the globle variable numberToCompute. numberToCompute = CInt(numericUpDown1.Value) ’ Reset the variable for percentage tracking. highestPercentageReached = 0 ’ Start the synchronous operation. result.Text = ComputeFibonacci(numberToCompute).ToString ’ Enable the UpDown control. Me.numericUpDown1.Enabled = True ’ Enable the Start button. startSyncButton.Enabled = True ’ Disable the Cancel button. cancelSyncButton.Enabled = False End Sub |
![]() 图二、即使函数在运行,但程序对用户操做没有任何反应 |
| Private Sub cancelSyncButton_Click(ByVal sender As System.Object,_ ByVal e As System.EventArgs) Handles cancelSyncButton.Click MsgBox("Cancel") End Sub |
上一篇: VB.NET中采用多线程填写treeview控件
下一篇: VB.NET中使用Directsound9之简单播放
| 关于我们 | 联系我们 | 广告服务 | 工作机会 | 版权声明 | 欢迎投稿 | 网站地图 |
| Copyright © 2000-2008 , www.21tx.com , All Rights Reserved . |
| © 晨新科技 版权所有 Created by TXSite.net |