Ask a questionAsk a question
 

AnswerToolstrip ProgressBar

  • Friday, January 18, 2008 8:12 PMultimatebuster Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    How do you use the progressbar of the toolstrip to display the loading of the webbrowser?

     

    thanks for anyone who replies

     

    Ultimatebuster

Answers

  • Monday, January 21, 2008 3:12 AMMartin Xie - MSFTMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi Ultimatebuster,

     

    Welcome to MSDN forums!

     

    In the WebBrowser_ProgressChanged event, you need to set the ToolStripProgressBar's Maximum and Value properties.

     

    In addition, you can show or hide the Progressbar based on that the webpage is being loaded or has been loaded.

     

    Here is the code sample.

    Prerequisites: WebBrowser1, ToolStrip1 and ToolStripProgressBar1 on Form1.

    Code Block

    Public Class Form1

     

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            WebBrowser1.Navigate("http://forums.microsoft.com")

        End Sub

     

        'Show the ToolStripProgressBar (optional)

        Private Sub WebBrowser1_Navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating

            ToolStripProgressBar1.Visible = True

        End Sub

     

        'Show the progress

        Private Sub WebBrowser1_ProgressChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged

            ToolStripProgressBar1.Maximum = Convert.ToInt32(e.MaximumProgress)

            ToolStripProgressBar1.Value = Convert.ToInt32(e.CurrentProgress)

        End Sub

     

        'Hide the ToolStripProgressBar (optional)

        Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

            ToolStripProgressBar1.Visible = False

        End Sub

     

    End Class

     

     

    Regards,

    Martin

     

     

     

All Replies

  • Monday, January 21, 2008 3:12 AMMartin Xie - MSFTMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi Ultimatebuster,

     

    Welcome to MSDN forums!

     

    In the WebBrowser_ProgressChanged event, you need to set the ToolStripProgressBar's Maximum and Value properties.

     

    In addition, you can show or hide the Progressbar based on that the webpage is being loaded or has been loaded.

     

    Here is the code sample.

    Prerequisites: WebBrowser1, ToolStrip1 and ToolStripProgressBar1 on Form1.

    Code Block

    Public Class Form1

     

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            WebBrowser1.Navigate("http://forums.microsoft.com")

        End Sub

     

        'Show the ToolStripProgressBar (optional)

        Private Sub WebBrowser1_Navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating

            ToolStripProgressBar1.Visible = True

        End Sub

     

        'Show the progress

        Private Sub WebBrowser1_ProgressChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged

            ToolStripProgressBar1.Maximum = Convert.ToInt32(e.MaximumProgress)

            ToolStripProgressBar1.Value = Convert.ToInt32(e.CurrentProgress)

        End Sub

     

        'Hide the ToolStripProgressBar (optional)

        Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

            ToolStripProgressBar1.Visible = False

        End Sub

     

    End Class

     

     

    Regards,

    Martin

     

     

     

  • Tuesday, November 03, 2009 8:18 PMyaip.net Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have a similar requirement but I want to show the progress of a file loading.
  • Wednesday, November 04, 2009 9:31 AMMartin Xie - MSFTMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi yaip,

    It depends on how you load a file.

    Here are two samples for you to check. Hope give you some ideas and hints.

    1. Show File Download Progress
    Download file from internet/website using HttpWebRequest and HttpWebResponse classes. 

    Prerequisites: Button1, Label1 and ProgressBar1 on Form1.

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

            Dim file As String = "http://URL/file.txt"

            Dim request As System.Net.WebRequest = System.Net.HttpWebRequest.Create(file)

            Dim response As System.Net.HttpWebResponse = request.GetResponse()

            Dim stream As System.IO.Stream = response.GetResponseStream()

            ' Get the length of the content

            Dim length As Integer = response.ContentLength

            ' Set the maximum length of the progress bar.

            ProgressBar1.Maximum = length

            ' Create a temporary array for the content of the file.

            Dim bytes(length) As Byte

            ' Get all bytes of the content and advance the progress bar.

            For i As Integer = 0 To length - 1

                bytes(i) = stream.ReadByte()

                ProgressBar1.Value = i

                Label1.Text = i.ToString + "Bytes Downloaded"

                Application.DoEvents()

            Next

            ' Write the content to the output file.

            Using output As IO.Stream = System.IO.File.Create("D:\Text.txt")

                output.Write(bytes, 0, bytes.Length)

            End Using

        End Sub


    2. Show Folder Copy Progress

    Prerequisites: Button1 and ProgressBar1 on Form1.

    Tigger ProgressBar increasing during copying files (in For Each Loop).

    Imports System.IO

    Public Class Form1

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

             Dim sourceFolder As New DirectoryInfo("C:\Dell")

            'FolderBrowserDialog1 is used to choose destination folder

            Dim FolderBrowserDialog1 As New FolderBrowserDialog

             If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

                Dim desFolder As DirectoryInfo

                If IO.Directory.Exists(FolderBrowserDialog1.SelectedPath & "\" & sourceFolder.Name) Then

                    desFolder = New DirectoryInfo(FolderBrowserDialog1.SelectedPath & "\" & sourceFolder.Name)

                Else

                    'Create the same name folder under the choosed destination folder

                    desFolder = Directory.CreateDirectory(FolderBrowserDialog1.SelectedPath & "\" & sourceFolder.Name)

                End If

            ProgressBar1.Maximum = sourceFolder.GetFiles("*", SearchOption.AllDirectories).Count

                 'Copy each file

                For Each file As FileInfo In sourceFolder.GetFiles("*", SearchOption.AllDirectories)

                    IO.File.Copy(file.FullName, desFolder.FullName & "\" & file.Name, True)

                    ProgressBar1.Value += 1

                Next

            End If

        End Sub

    End Class

     

    Best regards,
    Martin Xie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.