Member Avatar for Member #758415

Hello Daniweb, it's me (again).
I am making a web browser app and would like to have a loading bar. I'm using the default ProgressBar control but I don't know how to program it! Help!
Thanks for your help,
-Toby
--------------------------------------------------------------------------------------
If you put in your two pence worth, then someone, somewhere is making a penny.

Dani AI

Generated

is on the right track: use the WebBrowser.ProgressChanged event, but treat the event values as byte counts (they can be zero/negative or much larger than a ProgressBar’s default range). Map the downloaded bytes to your ProgressBar range, guard against division-by-zero and out-of-range assignments, and switch to an indeterminate (marquee) display when the total size is unknown. (learn.microsoft.com)

Here is a safe pattern to use (VB.NET):

Private Sub WebBrowser1_ProgressChanged(sender As Object, e As WebBrowserProgressChangedEventArgs) _
    Handles WebBrowser1.ProgressChanged

    If e.MaximumProgress <= 0 Then
        ProgressBar1.Style = ProgressBarStyle.Marquee
        ProgressBar1.MarqueeAnimationSpeed = 30
    Else
        ProgressBar1.Style = ProgressBarStyle.Continuous
        Dim total = Math.Max(1.0, CDbl(e.MaximumProgress))
        Dim current = Math.Max(0.0, CDbl(e.CurrentProgress))
        Dim percent = Math.Min(1.0, current / total)
        ProgressBar1.Value = CInt(Math.Round(percent * ProgressBar1.Maximum))
    End If

End Sub

Use the marquee style when total bytes are unknown; the ProgressBar.Style and MarqueeAnimationSpeed properties control that behavior. (learn.microsoft.com)

About the quit-sound: ’s idea to change play mode is relevant, but note his posted FileInfo/Exists usage won’t compile — IO.File.Exists expects a path string (or use FileInfo.Exists). If you want the app to wait for the sound to finish before exiting, play the WAV synchronously (or run the playback on a background task and close the form after it finishes). My.Computer.Audio.Play supports synchronous wait modes and only plays WAV resources. Example: play with AudioPlayMode.WaitToComplete (or use System.Media.SoundPlayer.PlaySync) when you need the sound to finish before exit. (learn.microsoft.com)

To verify execution order, set a breakpoint inside your click handler (click the left margin or press F9) and run with the debugger (F5). Step over/into (F10/F11) to watch the code path and variable values — that will quickly show whether the play call ever runs, which file path is used, and whether the close happens too soon. (learn.microsoft.com)

Recommended Answers

All 7 Replies

Member Avatar for Member #758415

And plus, we have coded our Quit button to play a sound then exit. It exits then plays no sound at all. This is our code:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim exitSound As String = "C:\stop.wav"
        If IO.File.Exists(exitSound) Then
            My.Computer.Audio.Play(exitSound)
        Else
            MsgBox("Application error. C:\stop.wav not found or corrupted. The app or file needs to be reinstalled.", MsgBoxStyle.Critical)
        End If
        Me.Close()
    End Sub
End Class

Use the .ProgressChanged Event of the Webbrowser you are using.

Private Sub WebBrowser1_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged
        ProgressBar1.Maximum = e.MaximumProgress
        ProgressBar1.Value = e.CurrentProgress
    End Sub

try this...

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
         Dim exitSound As String = "C:\stop.wav"         
         Dim fSound as New FileInfo(exitSound)
         If IO.File.Exists(fSound) Then            
            My.Computer.Audio.Play(exitSound, AudioPlayMode.Background)
         Else
            MsgBox("Application error. C:\stop.wav not found or corrupted. The app or file needs to be reinstalled.", MsgBoxStyle.Critical)
         End If
         Me.Close()
      End Sub
      End Class
Member Avatar for Member #758415

: Thanks!
: Sorry, not working.

the same coding which you provided is working for me.I mean it plays sound.did you check its order of execution with breakpoint.?


And plus, we have coded our Quit button to play a sound then exit. It exits then plays no sound at all. This is our code:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim exitSound As String = "C:\stop.wav"
        If IO.File.Exists(exitSound) Then
            My.Computer.Audio.Play(exitSound)
        Else
            MsgBox("Application error. C:\stop.wav not found or corrupted. The app or file needs to be reinstalled.", MsgBoxStyle.Critical)
        End If
        Me.Close()
    End Sub
End Class
Member Avatar for Member #758415

Breakpoint? What's Breakpoint? And how do I access it from VB2010?

how to implement keyascii with timer like as typing tutor..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.