Forum » Programiranje » [C#] WinForms - Buttons
[C#] WinForms - Buttons
GangStarr ::
Pozdravljeni!
Zanima me, kaj moram popraviti v spodnji kodi, da bo program deloval kot piše v navodilu. Hvala za pomoč.
Navodilo:
Change the program so that controls are only enabled when it makes sense, for example only the loadButton is enabled on startup, the stopButton is only enabled while loading is in progress, the continueButton is only enabled when loading is stopped …
Koda:
Zanima me, kaj moram popraviti v spodnji kodi, da bo program deloval kot piše v navodilu. Hvala za pomoč.
Navodilo:
Change the program so that controls are only enabled when it makes sense, for example only the loadButton is enabled on startup, the stopButton is only enabled while loading is in progress, the continueButton is only enabled when loading is stopped …
Koda:
public Form1() { InitializeComponent(); } public void loadButton_Click(object sender, EventArgs e) { textBox1.Text = "Loading..."; timer1.Enabled = true; progressBar1.Value = progressBar1.Minimum; } public void timer1_Tick(object sender, EventArgs e) { label1.Text = "Loaded: " + progressBar1.Value + "%"; if (progressBar1.Value == progressBar1.Maximum) { textBox1.Text = "Loaded!"; timer1.Enabled = false; } else progressBar1.PerformStep(); } public void stopButton_Click(object sender, EventArgs e) { timer1.Stop(); label1.Text = "Stopped"; if (textBox1.Text == "Loading") { stopButton.Enabled = true; } else { stopButton.Enabled = false; } } public void continueButton_Click(object sender, EventArgs e) { timer1.Start(); if (label1.Text == "Stopped") { continueButton.Enabled = true; } else { continueButton.Enabled = false; } }
Semper Fi
sebastjan28 ::
Saj vse piše v navodilih:) Za začetek, lahko poslušaš spremeniti sledeče....
public void loadButton_Click(object sender, EventArgs e)
{
loadButton.enabled = false;
textBox1.Text = "Loading...";
timer1.Enabled = true;
progressBar1.Value = progressBar1.Minimum;
}
public void stopButton_Click(object sender, EventArgs e)
{
timer1.Stop();
label1.Text = "Stopped";
if (textBox1.Text == "Loading")
{
stopButton.Enabled = true;
continueButton.Enabled = false;
}
else
{
stopButton.Enabled = false;
continueButton.Enabled = true;
}
}
public void continueButton_Click(object sender, EventArgs e)
{
timer1.Start();
if (label1.Text == "Stopped")
{
continueButton.Enabled = true;
stopButton.false = true;
}
else
{
continueButton.Enabled = false;
stopButton.Enabled = true;
}
}
public void loadButton_Click(object sender, EventArgs e)
{
loadButton.enabled = false;
textBox1.Text = "Loading...";
timer1.Enabled = true;
progressBar1.Value = progressBar1.Minimum;
}
public void stopButton_Click(object sender, EventArgs e)
{
timer1.Stop();
label1.Text = "Stopped";
if (textBox1.Text == "Loading")
{
stopButton.Enabled = true;
continueButton.Enabled = false;
}
else
{
stopButton.Enabled = false;
continueButton.Enabled = true;
}
}
public void continueButton_Click(object sender, EventArgs e)
{
timer1.Start();
if (label1.Text == "Stopped")
{
continueButton.Enabled = true;
stopButton.false = true;
}
else
{
continueButton.Enabled = false;
stopButton.Enabled = true;
}
}
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | C# PomočOddelek: Programiranje | 1400 (1225) | jizzer |
» | c# classOddelek: Programiranje | 2262 (1856) | japol |
» | Spremljanje dogajanja na ekranuOddelek: Programiranje | 1259 (1118) | boss-tech |
» | C# ProgramOddelek: Programiranje | 3095 (2018) | Spura |
» | c# ... kako je to mozno da Windows.Forms.Timer na istem threadu vec msg boxov pozeneOddelek: Programiranje | 1319 (1278) | Vapo1 |