Progress Bar
-
I have the following callback function which I am using to update a progress bar. The only problem is, when I change the value of the progress bar, the bar doesnt change:confused: It just shoots to 100 when it is done. I have tried using
Application.DoEvents();
.private Int32 CopyInProgress(uint TotalFileSize, uint BytesTransfered, uint StreamSize, uint StreamBytesTransfered, uint DwStreamNumber, long dwCallbackReason, long hSourceFile, long hDestinationFile, long lpData) { float t = TotalFileSize; float bt = StreamSize; int nPercent = (int)(bt/t)\* 100; percentComp.Text = nPercent.ToString() + "%"; progressBar.Value = nPercent; Application.DoEvents(); return PROGRESS\_CONTINUE; }
Any ideas why this is happening?
Sean :)
-
I have the following callback function which I am using to update a progress bar. The only problem is, when I change the value of the progress bar, the bar doesnt change:confused: It just shoots to 100 when it is done. I have tried using
Application.DoEvents();
.private Int32 CopyInProgress(uint TotalFileSize, uint BytesTransfered, uint StreamSize, uint StreamBytesTransfered, uint DwStreamNumber, long dwCallbackReason, long hSourceFile, long hDestinationFile, long lpData) { float t = TotalFileSize; float bt = StreamSize; int nPercent = (int)(bt/t)\* 100; percentComp.Text = nPercent.ToString() + "%"; progressBar.Value = nPercent; Application.DoEvents(); return PROGRESS\_CONTINUE; }
Any ideas why this is happening?
Sean :)
Yup, I got an idea. You are converting a float (bt/t) into an int...then multiplying it by 100. By definition, when you make it an int in this manner the answer can only be 0 or 100 and nothing in between. try changing it to: int nPercent = (int)(bt/t*100); :)
-
Yup, I got an idea. You are converting a float (bt/t) into an int...then multiplying it by 100. By definition, when you make it an int in this manner the answer can only be 0 or 100 and nothing in between. try changing it to: int nPercent = (int)(bt/t*100); :)
Nicely spotted! I was trying to find a reason why the message couldn't have reached the control. Tuh! Regards, Rob Philpott.
-
Nicely spotted! I was trying to find a reason why the message couldn't have reached the control. Tuh! Regards, Rob Philpott.
Not a problem. Even a crusty old C programmer gets to get one right once in a while. The rest of the time I'm generally walking around C# and .NET like a complete idiot because so many of the rules have been changed that there's not a lot of advantage to having programmed for 20+ years...LOL. Score: Cprogrammers = 1; WhizKids = INT_MAX; :)
-
Not a problem. Even a crusty old C programmer gets to get one right once in a while. The rest of the time I'm generally walking around C# and .NET like a complete idiot because so many of the rules have been changed that there's not a lot of advantage to having programmed for 20+ years...LOL. Score: Cprogrammers = 1; WhizKids = INT_MAX; :)