Wie man diese Funktion erstellt

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Wie man diese Funktion erstellt

by Anonymous » 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";

}

}
Wie kann diese Funktion für andere Progressba verwendet werden, anstatt neue Funktionen für jede Fortschrittsbuch zu wiederholen.

Top