在加载我的Web浏览器的进度条时出现轻微问题,每当我输入代码时,我的程序中的Windows.Forms.WebBrowserProgressChangedEventArgs部分出现问题,由于某种原因,它的表现就像是不正确的并试图找出这里到底出了什么问题。
Private Sub Loading(ByVal sender As Object, ByVal e As Windows.Forms.WebBrowserProgressChangedEventArgs)
ToolStripProgressBar1.Maximum = e.MaximumProgress
ToolStripProgressBar1.Value = e.MaximumProgress
End Sub
Private Sub Done(ByVal sender As Object, ByVal e As Windows.Forms.WebBrowserDocumentCompletedEventArgs)
TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle
ComboBox1.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString
End Sub
答案 0 :(得分:0)
您每次都将value
设置为maximum
,因此无法正确显示。
但是 - 您不应该使用MaxiumProgress
来设置进度条的Maximum
值,因为MaximumProgress
是Long
并且ProgressBar Value
是Integer
,因此如果您有一个大文档,它可能会溢出。
您应该做的是计算百分比进度并显示:
Private Sub WebBrowser1_ProgressChanged(sender As Object, e As WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged
Dim percentage As Integer
'calculate the percentage checking for zero maximum as an error case
If e.MaximumProgress = 0 Then
percentage = 0
Else
percentage = CInt(e.CurrentProgress / e.MaximumProgress * 100)
End If
'make sure it is in bounds of the progress bar
If percentage >= 0 AndAlso percentage <= ToolStripProgressBar1.Maximum Then
'set the value
ToolStripProgressBar1.Value = percentage
End If
End Sub
Private Sub WebBrowser1_Navigated(sender As Object, e As WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
'set the value to zero when we have finished
ToolStripProgressBar1.Value = 0
End Sub
现在您可以将进度条最小值设置为0,将最大值设置为100(这是默认值)