Results 1 to 21 of 21

Thread: Getting toolStripProgressBar to Increment

  1. #1

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Question Getting toolStripProgressBar to Increment

    the code below works but its not Incrementing One Block at a time as the Browser is loading....Goes from Empty to Full ...

    Code:
     if (toolStripProgressBar1.Value == toolStripProgressBar1.Maximum)
                {
                    toolStripProgressBar1.Value = toolStripProgressBar1.Minimum;
                }
                for (int i = toolStripProgressBar1.Minimum; i <= toolStripProgressBar1.Maximum; i++)
                {
                    toolStripProgressBar1.PerformStep();
    
                }
    Thxs for the help in advance...

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting toolStripProgressBar to Increment

    That loop will be executed so quickly that you won't see the intermediate steps.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: Getting toolStripProgressBar to Increment

    Ok so what do i need to do too fix it then?

  4. #4

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: Getting toolStripProgressBar to Increment

    I set the Value to 5 in the Properties Box still goes really fast thou...lol

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting toolStripProgressBar to Increment

    You need to slow down the loop, which is what the operation that you are showing the progress for would normally do.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting toolStripProgressBar to Increment

    Ah, I just realised that I misread your original post and this is supposed to be showing the progress of a Web page loading. There's no connection between the code you've posted and the browser though. That loop is just going to zip straight from min to max in no time flat. I've never used a browser control myself but I believe that it has events that indicate loading progress. Take a look at the WebBrowser.ProgressChanged event.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: Getting toolStripProgressBar to Increment

    Code:
    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                if (toolStripProgressBar1.Value == toolStripProgressBar1.Maximum)
                {
                    toolStripProgressBar1.Value = toolStripProgressBar1.Minimum;
                }
                for (int i = toolStripProgressBar1.Minimum; i <= toolStripProgressBar1.Maximum; i++)
                {
                    toolStripProgressBar1.PerformStep();
                }
    When i change the webBrowser1_DocumentCompleted to webBrowser1_DocumentCompletedEventHandler the progressbar stops working all together..lol

    Thier is a
    Code:
    WebBrowser.ControlAccessibleObject(ProgressBar);
    but not sure how too implement it into the code above..If you change from DocumentCompleted the Loop for the ProgressBar just stops working..

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting toolStripProgressBar to Increment

    After a little bit of phaffing about, this seems to work:
    Code:
    private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
    {
        if (e.CurrentProgress <= 0)
        {
            this.progressBar1.Value = 0;
        }
        else
        {
            this.progressBar1.Value = Math.Min(this.progressBar1.Maximum, 
                                               Convert.ToInt32(Math.Floor(this.ProgressBar1.Maximum * (e.CurrentProgress / e.MaximumProgress))));
        }
    }
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: Getting toolStripProgressBar to Increment

    Error::

    Error 1 The call is ambiguous between the following methods or properties: 'System.Math.Floor(decimal)' and 'System.Math.Floor(double)' C:\Documents and Settings\Jerry\My Documents\Visual Studio 2005\Projects\MediaViewer\MediaViewer\Form1.cs 94 60 MediaViewer

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting toolStripProgressBar to Increment

    Hmmm... I wrote and tested the code in VB Express by mistake, so I just wrote the C# equivalent and posted it. It doesn't really matter. You're dividing a long by a long and then multiplying by an int. It doesn't matter whether the result is a double or a decimal as you're going to convert it to an int anyway, so just pick one and cast as that before passing to Floor.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: Getting toolStripProgressBar to Increment

    ok you kinda lost me at the end their " so just pick one and cast as that before passing to Floor." ??

    Not sure what you mean by pick one and cast as that before passing to floor..

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting toolStripProgressBar to Increment

    The compiler doesn't know whether the expression that you're passing to Math.Floor is a double or a decimal, so just pick one and cast. You've got this:
    Code:
    Math.Floor(this.ProgressBar1.Maximum * (e.CurrentProgress / e.MaximumProgress))
    so either pick double and cast:
    Code:
    Math.Floor((double)(this.ProgressBar1.Maximum * (e.CurrentProgress / e.MaximumProgress)))
    or pick decimal and cast:
    Code:
    Math.Floor((decimal)(this.ProgressBar1.Maximum * (e.CurrentProgress / e.MaximumProgress)))
    Either way you are specifically telling the compiler that the result of the expression should be that particular type so it knows which overload of Math.Floor to call. Which you choose is irrelevant because when you floor it and convert to an int you end up with the same thing. This issue didn't arise in VB because the result of that expression was automatically a Double.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: Getting toolStripProgressBar to Increment

    That fixed the Error but the toolStripProgressBar1 dosnt even move for some reason

  14. #14
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting toolStripProgressBar to Increment

    OK, I'm too used to VB doing things for me. You need to cast everything as double or decimal before doing the calculations. I guess things get rounded off otherwise.
    Code:
    double curProg = Convert.ToDouble(e.CurrentProgress);
    double maxProg = Convert.ToDouble(e.MaximumProgress);
    double maxVal = Convert.ToDouble(this.toolStripProgressBar1.Maximum);
    
    this.toolStripProgressBar1.Value = Math.Min(this.toolStripProgressBar1.Maximum, Convert.ToInt32(Math.Floor(maxVal * (curProg / maxProg))));
    You could use casts and do this all on the same line if you want but I think this is clearer as an example.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  15. #15

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: Getting toolStripProgressBar to Increment

    maybe it needs
    Code:
    webBrowser webBrowser1_DocumentCompleted = new WebBrowser(webBrowser_DocumentCompleted);
    Something along those lines for it to work?? because it just dosnt want too work with out the webBrowser1_DocumentCompleted..


    Code:
     private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
            {
                if (e.CurrentProgress <= 0)
                {
                    this.toolStripProgressBar1.Value = 0;
                }
                else
                {
                    double curProg = Convert.ToDouble(e.CurrentProgress);
                    double maxProg = Convert.ToDouble(e.MaximumProgress);
                    double maxVal = Convert.ToDouble(this.toolStripProgressBar1.Maximum);
    
                    this.toolStripProgressBar1.Value = Math.Min(this.toolStripProgressBar1.Maximum, Convert.ToInt32(Math.Floor(maxVal * (curProg / maxProg))));
                }
            }

  16. #16
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting toolStripProgressBar to Increment

    What I just posted was tested in C# 2005 Express and worked fine for me. The progress increases as the page loads and then goes back to zero when it's done. What do you hope to accomplish using the DocumentCompleted event? The page has finished loading when that event is raised so how is that supposed to give you loading progress? The code I provided will show progress as it's reported by the WebBrowser control. You cannot show a more accurate progress than that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  17. #17

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: Getting toolStripProgressBar to Increment

    Code:
    private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
            {
                if (e.CurrentProgress <= 0)
                {
                    this.toolStripProgressBar1.Value = 0;
                }
                else
                {
                    double curProg = Convert.ToDouble(e.CurrentProgress);
                    double maxProg = Convert.ToDouble(e.MaximumProgress);
                    double maxVal = Convert.ToDouble(this.toolStripProgressBar1.Maximum);
                    this.toolStripProgressBar1.Value = Math.Min(this.toolStripProgressBar1.Maximum, Convert.ToInt32(Math.Floor(maxVal * (curProg / maxProg))));
                }
            }
    Correct?? because for some reason its giving me trouble..

    Properites Panel :: Step 5
    Value 0
    Enabled = true
    Style Blocks

  18. #18
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting toolStripProgressBar to Increment

    The Style is irrelevant, as is the Step. Step is the value by which the Value will increase when you cal PerformStep. You're not doing that so it has no influence. The progress bar will change when the WebBrowser notifies it. The progress will not be smooth and ther may be fits and starts. You have to live with that because the only information you have to go on is what the WebBrowser provides you in the ProgressChanged event handler.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  19. #19

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: Getting toolStripProgressBar to Increment

    I understand but what gets me is it dosnt move at all even if i let sit thier for a few minutes...lol

  20. #20
    New Member
    Join Date
    Feb 2011
    Posts
    1

    Re: Getting toolStripProgressBar to Increment

    I simply copied and pasted your code in my webBrowser application. And it is working fine.
    Unnikrishnan, India.

  21. #21
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: Getting toolStripProgressBar to Increment

    Just to check, the webBrowser1_ProgressChanged method is hooked up to the ProgressChanged event on the webBrowser1 control, right?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width