Wie man diese Funktion erstellt
Posted: 28 Feb 2025, 08:55
Code: Select all
private void LoadProgressBar1(Label label)
{
int labelValue;
if (int.TryParse(label.Text, out labelValue))
{
int total = 120;
int progressValue = (int)Math.Round((labelValue / (double)total) * 100);
progressValue = Math.Max(0, Math.Min(100, progressValue));
progressBar1.Style["width"] = progressValue + "%";
if (progressValue < 50)
progressBar1.Style["background-color"] = "green";
else if (progressValue < 80)
progressBar1.Style["background-color"] = "orange";
else
progressBar1.Style["background-color"] = "red";
}
}
private void LoadProgressBar2(Label label)
{
int labelValue;
if (int.TryParse(label.Text, out labelValue))
{
int total = 50;
int progressValue = (int)Math.Round((labelValue / (double)total) * 100);
progressValue = Math.Max(0, Math.Min(100, progressValue));
progressBar2.Style["width"] = progressValue + "%";
if (progressValue < 50)
progressBar2.Style["background-color"] = "green";
else if (progressValue < 80)
progressBar2.Style["background-color"] = "orange";
else
progressBar2.Style["background-color"] = "red";
}
}
Code: Select all