|
-
Mar 3rd, 2006, 02:32 AM
#1
Thread Starter
Hyperactive Member
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...
-
Mar 3rd, 2006, 02:40 AM
#2
Re: Getting toolStripProgressBar to Increment
That loop will be executed so quickly that you won't see the intermediate steps.
-
Mar 3rd, 2006, 02:41 AM
#3
Thread Starter
Hyperactive Member
Re: Getting toolStripProgressBar to Increment
Ok so what do i need to do too fix it then?
-
Mar 3rd, 2006, 02:47 AM
#4
Thread Starter
Hyperactive Member
Re: Getting toolStripProgressBar to Increment
I set the Value to 5 in the Properties Box still goes really fast thou...lol
-
Mar 3rd, 2006, 02:52 AM
#5
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.
-
Mar 3rd, 2006, 02:56 AM
#6
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.
-
Mar 3rd, 2006, 03:47 AM
#7
Thread Starter
Hyperactive Member
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..
-
Mar 3rd, 2006, 04:32 AM
#8
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))));
}
}
-
Mar 3rd, 2006, 01:50 PM
#9
Thread Starter
Hyperactive Member
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
-
Mar 3rd, 2006, 06:12 PM
#10
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.
-
Mar 3rd, 2006, 06:24 PM
#11
Thread Starter
Hyperactive Member
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..
-
Mar 3rd, 2006, 06:40 PM
#12
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.
-
Mar 3rd, 2006, 07:02 PM
#13
Thread Starter
Hyperactive Member
Re: Getting toolStripProgressBar to Increment
That fixed the Error but the toolStripProgressBar1 dosnt even move for some reason
-
Mar 3rd, 2006, 07:21 PM
#14
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.
-
Mar 3rd, 2006, 07:36 PM
#15
Thread Starter
Hyperactive Member
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))));
}
}
-
Mar 3rd, 2006, 07:41 PM
#16
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.
-
Mar 3rd, 2006, 07:46 PM
#17
Thread Starter
Hyperactive Member
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
-
Mar 3rd, 2006, 08:12 PM
#18
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.
-
Mar 3rd, 2006, 09:11 PM
#19
Thread Starter
Hyperactive Member
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
-
Feb 26th, 2011, 06:55 PM
#20
New Member
Re: Getting toolStripProgressBar to Increment
I simply copied and pasted your code in my webBrowser application. And it is working fine.
Unnikrishnan, India.
-
Feb 27th, 2011, 08:04 PM
#21
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|