我正在尝试将进度条的百分比打印到文本框中。当我运行程序时,文本框中没有任何内容。这是我的代码:
Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
ProgressBar1.Maximum = TextBox1.Text
End Sub
非常感谢帮助!谢谢。
答案 0 :(得分:1)
以下是我为您编写的一些代码,它应该引导您朝着正确的方向前进并为您提供帮助:)
Imports System.ComponentModel
Public Class Form1
''This will display the information to the textbox and will also load a progressbar(you can change it to something else beside a textbox too eg label, windows form title and so on).
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
TextBox1.Text = e.ProgressPercentage & "%"
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
''This is make the backgroundworker start at load up(change it to a button if need be
CheckForIllegalCrossThreadCalls = False
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork
''This is the example that i created to show you how to set a task.
For i = 0 To 10000
TextBox1.Text = i
BackgroundWorker1.ReportProgress(i)
System.Threading.Thread.Sleep(500)
Next
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
''once the task is complete it will show a messagebox and reset the progressbars value to 0 so its not full when the task is compelete.
MessageBox.Show("Completed")
ProgressBar1.Value = 0
End Sub
结束班
让我知道你怎么走,我住在一个我无法访问你发布的网站链接的国家。
快乐编码
更新:请查看google上的后台工作人员,有很多教程可以帮助您:)