我创建了一个Bingo机器,可以调用和检查已调用的数字。一旦用户呼叫房屋,游戏将暂停,并将使用单独的表格来检查数字。这个单独的表格有1-90的数字,并将全部突出显示。我的问题是,如何突出显示已被调出的最后一个数字?
要求突出显示的所有号码的代码:
private void btnCheckNumbs_Click(object sender, EventArgs e)
{
//Check to see what numbers have been called by calling on Global Variables.
for (int i = 1; i <= Globals.NextBalls; i++)
{
for (int k = 1; k <= 90; k++)
{
if (Globals.balls[i] == k)
{
TextBox txtName = (TextBox)this.Controls.Find("txtBoxs" + k.ToString(), true)[0];
txtName.BackColor = Color.Crimson;
}
}
}
这是Next Balls的代码,基本上txtBoxMainNo是显示要调用的最后一个数字的文本框。
// Timer of the game
private void GameTimer1_Tick(object sender, EventArgs e)
{
Globals.balls[1] = 1;
txtboxMainNo.Text = Convert.ToString(Globals.balls[Globals.NextBalls]);
Globals.NextBalls = Globals.NextBalls + 1;
SpVoice obj = new SpVoice();
int i = Convert.ToInt32(txtboxMainNo.Text);
obj.Speak(Globals.bingocomments[i], SpeechVoiceSpeakFlags.SVSFDefault);
if (Globals.NextBalls >= 91) { GameTimer1.Enabled = false; }
}
答案 0 :(得分:0)
嘿,如果您只想突出显示最后一个元素,我只需添加一个List并获取最后一个索引。然后突出显示该元素的颜色。
private void btnCheckNumbs_Click(object sender, EventArgs e)
{
var list = new List<TextBox>();
//Check to see what numbers have been called by calling on Global Variables.
for (int i = 1; i <= Globals.NextBalls; i++)
{
for (int k = 1; k <= 90; k++)
{
if (Globals.balls[i] == k)
{
TextBox txtName = (TextBox) this.Controls.Find("txtBoxs" + k.ToString(), true)[0];
list.Add(txtName);
}
}
}
list.Last().BackColor = Color.Crimson;
}