According to msdn:
The number of bytes that have been loaded or -1 to indicate that the download has completed.
And the -1 value is not valid progress value. And it indicates that download has completed so displaying progressbar is pointless. I think this state would be good place to hide progress window.
In your code you are casting form long
to int
which will cause you similar exception when you download file which size will be greater then 2,147,483,647 bytes (int.MaxValue). You should assign
toolStripProgressBar1.Maximum = 100;
and in event
toolStripProgressBar1.Value = (int)Math.Floor((e.CurrentProgress / (double)e.MaximumProgress) * 100);