Hallo Forum Gemeinschaft
Ich habe Problem mit darstellen von ForeColor , BackColor Label.Text
Ich habe eine Uhr programmiert .Nach beenden des Tieme soll die Farbe von Fore und Back geändert werden , leider sofort nach dem Start ändert sich die Farbe von Back und Fore und das Time wird angehalten .Was mache ich falsch ?
Hier das Code
namespace Uhr0001
{
public partial class Form1 : Form
{
private TimeSpan timeleft;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
timeleft = new TimeSpan(0, 0, 10);
LblTimer.Text = timeleft.ToString(@"hh\:mm\:ss");
timerCountdown.Start();
}
private void timerCountdown_Tick(object sender, EventArgs e)
{
timeleft = timeleft.Subtract(TimeSpan.FromSeconds(1));
LblTimer.Text = timeleft.ToString(@"hh\:mm\:ss");
if (timeleft.TotalSeconds <= 0)
timerCountdown.Stop();
this.LblTimer.AutoSize = true;
this.LblTimer.Text = "Zeit";
this.LblTimer.ForeColor = Color.Red;
this.LblTimer.BackColor = Color.Black;
}
private void LblTimer_Click(object sender, EventArgs e)
{
}
}
}
Bitte [Hinweis] Wie poste ich richtig? beachten und Dein Code in Tags packen.
Niemand hat Lust Plaintext zu lesen. Danke.
Edit: schade, dass das andere für Dich tun müssen, wenn Du Dich Hilfe suchst 😉
- performance is a feature -
Microsoft MVP - @Website - @AzureStuttgart - github.com/BenjaminAbt - Sustainable Code
Hi,
du setzt die Farbe im Tick immer zurück, weil du keine Brackets für dein IF verwendest.
Gruß,
Thomas
u setzt die Farbe im Tick immer zurück, weil du keine Brackets für dein IF verwendest
wie soll Brackets aussehen ?
Er meint geschweifte Klammern.
if (timeleft.TotalSeconds ≤ 0)
{
timerCountdown.Stop();
this.LblTimer.AutoSize = true;
this.LblTimer.Text = "Zeit";
this.LblTimer.ForeColor = Color.Red;
this.LblTimer.BackColor = Color.Black;
}
T-Virus
Developer, Developer, Developer, Developer....
99 little bugs in the code, 99 little bugs. Take one down, patch it around, 117 little bugs in the code.
Danke
werde ausprobieren