Hello team,
I have a UltraStatusBar and added a Panel whose style is set to Progress. I want to show the user the progress of a long running process with its value. I set the Minimum as 0 and Maximum values as 100.
Now my I have a loop which runs for 265 iterations. Under this loop i am trying to update the ProgressBarInfo value as below, does not seem mathematically correct though :)
ultraStatusBar1.Panels["TestProgress"].ProgressBarInfo.Value =1;
for(int i=0;i<265;i++)
{
if( ultraStatusBar1.Panels["TestProgress"].ProgressBarInfo.Value < 100 && (ultraStatusBar1.Panels["TestProgress"].ProgressBarInfo.Value + 100 / 265 < 100)) { ultraStatusBar1.Panels["TestProgress"].ProgressBarInfo.Value += 100 / 265; }
}
I guess the ProgressBarInfo.Value will only increment by 1 and since my loop has to run for 265 times 100/265 gives me a value of 0.377, the value is not getting incremented by this decimal value.
Could you suggest me a logic so that I can show the Progress to the user with 265 iterations when ProgresBarInfo Minimum as 0 and Maximum values as 100?
Any suggestions are highly appreciated.
Hello,
Thank you for posting. Try to set its maximum values to 265 and so that instead of getting a decimal value you will get integer and value keep incrementing.
Please let me know if it helps or needs further assistance.
Thank you Divya.
Setting the maximum value to 265 will surely increment the ProgressBarInfo value, but I do not want the user to see that the loop runs for 265 times. The value should be displayed between 1-100 when though the loop runs for 265 times. Its like process running and the user wants to see how much % of processing is left.
I'm not sure I understand the distinction you are making here.
It's generally not a good idea to update the ProgressBar by adding to it's current value. This makes things complicated, because you can run into rounding errors. It's better practice, in my experience to explicitly set the Value to something that indicates how far along your process has progressed.
If your process has X steps, then the simplest thing to do is to set the Minimum to 0 and the Maximum to X, and then set the Value of the progress bar to how many steps are completed. The ProgressBar will fill a percentage of the bar based on how much of the process is complete: (value/MaxValue). The ProgressBar figures out how much to show as filled. So what is it that you want that you are not able to achieve?
Another approach you could potentially take (but that will give you essentially the same results) is to use 0 and 100 as you Minimum and Maximum respectively. But in that case, it would be your responsibility to do the math and convert you current step (i) and the maximum step (X) into a value from 1 to 100. Which is simple enough to do, you just use "i/X * 100". It's a little trickier than that, because you can't easily divide two integers without some casting, but it's not terribly hard.
Beyond that, I'm not sure what you are asking.
I have attached a sample project here that demonstrates both approaches.
1581.WindowsFormsApplication1.zip
Thank you Mike.
This is what exactly I was looking at. Maybe I could not put my question in proper words, but you got my problem
Thank you for providing me a sample code as well, below is the code more or less I was looking for.
for (int i = 0; i <= 265; i++) { double percentageD = ((double)i / (double)265) * 100; int percentage = (int)percentageD; progressBarPanel1.ProgressBarInfo.Value = percentage; this.ultraStatusBar1.Refresh(); }
A quick question though, when I set the ShowLabel property of the ProgressBarInfo to false, is there a way for me to still show the progress without displaying any value/percentage of the process running? something like a UltraProgressBar control does?
Thank you for the update.I am glad that you found the solution to your requirement.
The above logic does not work for my scenario. I was able to achieve my need using a different workaround. Added another panel to the status bar control and set its style to Control container. This panel holds the ActivityIndicator control which shows the progress of my long running process.
Hello ,
Thank you for the update.
When you set ProgressBarInfo.ShowLabel to false it still shows the progress without showing the value and percentage of the progress so I am not sure what you are trying to achieve.
If you are trying to just change the label and shows the percentage of the ProgressBarInfo then you can use label property, like this:
progressBarPanel2.ProgressBarInfo.Label = "%";
Please let me know if you need further assistance.