» »

[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:
        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;
    }
}

GangStarr ::

Hvala, hvala :)
Semper Fi


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

C# Pomoč

Oddelek: Programiranje
131400 (1225) jizzer
»

c# class

Oddelek: Programiranje
342262 (1856) japol
»

Spremljanje dogajanja na ekranu

Oddelek: Programiranje
81259 (1118) boss-tech
»

C# Program

Oddelek: Programiranje
393095 (2018) Spura
»

c# ... kako je to mozno da Windows.Forms.Timer na istem threadu vec msg boxov pozene

Oddelek: Programiranje
51319 (1278) Vapo1

Več podobnih tem