1

I included a download option in my Windows application. I would like to update the progress bar result as per my calculated percentage. I calculated the percentage in one class and used yield return to return the percentage:

 int percertage = ((int)(((decimal)Offset / (decimal)FileSize) * 100));
 yield return "Percentage: " + percertage.ToString() + "%";

How do I assign it to my progress bar update the value according to the percentage?

2 Answers 2

1

In the progress bar we have a function called PerformStep() using which we can make the progress of the progress bar increase slightly.

pBar1.PerformStep();
7
  • ya checked out this function but i am downloading 5mb files but the progress bar is finished before the download completed.....and i also used the progressBar3.Step = 1; progressBar3.Minimum = 0; progressBar3.Maximum = 450; also in that the maxim value is not fixed for every file right ....if iam downloading 10mb file thi maximum value not suit so is there any suggestion for this prob Sep 13, 2011 at 4:46
  • then, assign the value of the percentage you calculated to the progressbar.value as suggested by deepi. Sep 13, 2011 at 4:50
  • i got another prob actually i am returning this three from oneclass yield return "Percentage : " + percertage.ToString() +"%" ; yield return percertage.ToString(); yield return SummaryText; Sep 13, 2011 at 7:37
  • Now the thing is in my main class i need to get all the return values from that class so i used this code foreach (string str in objDownload.ClientDownload()){if (str.ToLower().Contains("percentage")){ lblPercentage.BeginInvoke((MethodInvoker)delegate { lblPercentage.Text = str; }); progressBar3.BeginInvoke((MethodInvoker)delegate { progressBar3.Value = int.Parse(str); }); Sep 13, 2011 at 7:38
  • i am getting error because in progressBar3.Value = int.Parse(str); this str contains three values that i am returning from another class so input string is not in correct format dono how to solve this..plz tell what i have to Sep 13, 2011 at 7:39
1

try this:

int percertage= ((int)(((decimal)Offset / (decimal)FileSize) * 100));
pgbrValue.Value = percertage;//it's in C#
yield return "Percentage : " + percertage.ToString() + "%";
4
  • i got another prob actually i am returning this three from one class yield return "Percentage : " + percertage.ToString() +"%" ; yield return percertage.ToString(); yield return SummaryText; Now the thing is in my mail class i need to get all the return values from that class so i used this code foreach (string str in objDownload.ClientDownload()){if (str.ToLower().Contains("percentage")){ lblPercentage.BeginInvoke((MethodInvoker)delegate { lblPercentage.Text = str; }); progressBar3.BeginInvoke((MethodInvoker)delegate { progressBar3.Value = int.Parse(str); }); Sep 13, 2011 at 7:29
  • i am getting error because in progressBar3.Value = int.Parse(str); this str contains three values that i am returning from another class so input string is not in correct format dono how to solve this..plz tell what i have to do Sep 13, 2011 at 7:36
  • take global variable and after getting percentage assign that to one of the global variable. so you can directly get that value without returning
    – deepi
    Sep 13, 2011 at 7:44
  • thanks yaar its working.i just assign to a static variable and called in my main function its working good....thank u so much Sep 13, 2011 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.