0

Form1 に次のコードがあります。

public partial class Form1 : Form
{
    public static int hours;
    public static int minutes;
    public static int seconds;
    FinishGate finishgate = new FinishGate();

    public Form1()
    {
        InitializeComponent();

        txtHours.MaxLength = 2;
        txtMinutes.MaxLength = 2;
        txtSeconds.MaxLength = 2;

        lblFinished.Text = Convert.ToString(gate.Total);
    }

private void btnFinish_Click(object sender, EventArgs e)
    {
        hours = Convert.ToInt32(txtHours.Text);
        minutes = Convert.ToInt32(txtMinutes.Text);
        seconds = Convert.ToInt32(txtSeconds.Text);
        lblFinished.Text = Convert.ToString(gate.Total);

        // Check if a runner has been selected
        if (lstRunners.SelectedIndex > -1)
        {
            // Obtain selected runner
            Runner selectedRunner = (Runner)lstRunners.SelectedItem;

            // If runner hasn't finished
            if (selectedRunner.HasFinished == false)
            {
                // Call the method in FinishGate class to process the runner
                FinishGate.ProcessRunner(selectedRunner);
            }
            else
            {
                // Runner has finished / been processed so increase the total that have completed the climb by one
                finishgate.Total++;
            }
        }
    } 
}

FinishGate.cs は次のとおりです。

class Gate
{
    private int total;

    public int Total
    {
        get { return total; }
        set { total = value; }
    }

    public static void ProcessRunner(Runner selectedRunner)
    {

    }
}

私がしたいのは、リストボックス内のランナーが選択され、[プロセス] ボタンがクリックされると、ブール値hasFinishedが にProcessRunner変更されtrueTotal整数が 1 増加し、それlblFinishedによって も 1 増加するように更新されることですが、できません。それを機能させます。

私の2つの主な問題は次のとおりです。trueに変更したProcessRunner()場合、コードが何を意味するのかわかりません。ブール値をそのままにしておきます。もう 1 つの問題は、整数が増加したときにそれに応じて を更新することです。hasFinished == falseelselblFinished

私が間違っている場所と、将来これを防ぐ方法についてのアドバイスは素晴らしいでしょう.

4

1 に答える 1