注册 登录
编程论坛 VB.NET论坛

请大神帮看看

角角鱼 发布于 2013-01-13 23:28, 555 次点击
红色部分为不清楚的部分,那位知道在那里改?先谢谢了,(目前其他的功能基本上都实现了)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Try
            BackgroundWorker1.RunWorkerAsync()
           我该在哪里确定progeessbar的最大值?目前我乱放在这的
            ProgressBar1.Maximum = 1000000
            While Me.BackgroundWorker1.IsBusy
                Application.DoEvents()
            End While
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString())
        End Try

    End Sub

    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As ) Handles BackgroundWorker1.DoWork
        Dim url As String = "http://www.
        Try
            Dim resquert As WebRequest = HttpWebRequest.Create(url)
             = 512
            resquert.Timeout = 500
            Dim response As HttpWebResponse = resquert.GetResponse()
            Dim length As Long = response.ContentLength
             '曾经在将progressbar的MAX值放在这,但报错
            Do
                Dim nread As Integer
                Dim readbuffer(4096) As Byte
                Dim readbyte As Long = response.GetResponseStream.Read(readbuffer, 0, 4096)
                nread += readbyte
                BackgroundWorker1.ReportProgress(nread)
                If readbyte = 0 Then Exit Do
            Loop
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString())
        End Try

    End Sub


    Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As System.Object, ByVal e As ) Handles BackgroundWorker1.ProgressChanged
        ProgressBar1.Value = e.ProgressPercentage
        Label1.Text = ProgressBar1.Value
    End Sub
1 回复
#2
角角鱼2013-01-13 23:29
注:那个100000是我自己乱加上的
1