I am trying to make a color changing mehapps metroui progress bar based on the percentage of the file that is downloaded. In lua I do like so:
ARGB(255, 255 * percent, 255 - (255 * percent), 0)
Now in trying to do this in C#:
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
label2.Content = "Downloaded " + (e.BytesReceived / 1000) + "kb" + " of " + (e.TotalBytesToReceive / 1000) + "kb" + " (" + Math.Round(percentage) + "%)";
progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
Color myColor = Color.FromArgb(255, 255 * (Math.Round(percentage)), 255 - (255 * (Math.Round(percentage))), 0);
string hex = myColor.R.ToString("X2") + myColor.G.ToString("X2") + myColor.B.ToString("X2");
Console.WriteLine(hex);
}
The label2 works great but the mycolor line errors out with:
Cannot convert from double to byte.
I even tried using progressBar1.Value
and get the same error. What am I doing wrong? Is there an easier way to just make my progress bar go from red to green based on percentage downloaded?