I have noticied that when using the PorgressBar. If I set the value to x, the value displayed is not immediately updated, it takes a small amount of time to draw it as the bar is animated from its current value to the new value.
This is easy to see in the following code:
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label1.Text = ""
Dim progressHandler = New Progress(Of Integer)(Sub(value) ProgressBar1.Value = value)
Dim progress = CType(progressHandler, IProgress(Of Integer))
Await Task.Run(Sub()
For i = 1 To 100
progress.Report(i)
Thread.Sleep(10)
Next
End Sub)
Label1.Text = "Value Now at 100%"
Await Task.Delay(650) 'it takes this long for the bar to be rendered
Label1.Text += " - Finished drawing"
End Sub
You will notice running this code that the Value Now at 100% appears a long time before the bar has actually reached 100%.
Is there any way that I can detect when the bar has finished rendering?
I just tried this out and can see exactly what you mean. Unfortunately after spending a little while seeing if the DrawToBitmap functions on the progress bar might help, I’ve come up short.
The next step would be to create a custom progress bar that exposes events for when rendering has completed.
For a reasonable example on how to create a custom progress bar, try here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.progressbarrenderer(v=VS.100).aspx
A quick scan over the code looks like you should be able to plug in an ‘OnRendered’ event or similar on or around the calls to ‘DrawHorizontalChunks’ (or ‘DrawVerticalChunks’).
Probably not the answer you was after, but at least gives you the control you need if you pursue it?
Note: I haven’t tried this myself, so please don’t send me hate mail if you spend all day on this to find you get the same results…
Good Luck!
EDIT:
Wasn’t happy with my response, seemed a bit lazy… The following uses a custom progress bar as I described. It has a couple basic properties for setting Max/Min values, Performing steps, and setting the value directly. I’ve tested this by changing the sleep interval to various amounts, in all cases the form displayed the progress bar as full before closing. Note the new OnRendered event.