我的 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)
{
}
}
What I want to happen is that when a runner in the listbox is selected and the Process button is clicked, the boolean hasFinished
in ProcessRunner
is changed to true
and the Total
integer is increased by one, which then updates the lblFinished
to also increase by one, but I can'让它工作。
我的两个主要问题是:如果将其更改为 true,我不确定代码会ProcessRunner()
说什么,让布尔值保持原样。另一个问题是当整数增加时相应地更新。hasFinished == false
else
lblFinished
关于我哪里出错以及将来如何防止这种情况的任何建议都会很棒。