TextBox[] textArray = new TextBox[] { numText1, numText2, numText3, numText4, numText5, numText6, numText7, numText8 };
if (stepButton.Text == "開始")
{
stepButton.Text = "下一步";
for (int i = 7; i > 0; i--)
{
for (int j = 0; j < i; j++)
{
if (int.Parse(textArray[j].Text) > int.Parse(textArray[j + 1].Text))
{
string tmp = textArray[j + 1].Text;
textArray[j + 1].Text = textArray[j].Text;
textArray[j].Text = tmp;
}
}
}
for (int i = 0; i < 8; i++)
textArray[i].BackColor = Color.LightBlue;
targetText.Enabled = false;
}
else
{
int i, lowIndex = 0, highIndex = 0;
for (i = 0; i < 8; i++)
if (textArray[i].BackColor == Color.LightBlue)
break;
lowIndex = i;
for (i = 7; i > 0; i--)
if (textArray[i].BackColor == Color.LightBlue)
break;
highIndex = i;
for (i = 0; i < 8; i++)
textArray[i].BackColor = SystemColors.Window;
int midIndex = (highIndex + lowIndex) / 2;
if (textArray[midIndex].Text == targetText.Text)
{
MessageBox.Show("你所指定的數字在索引 " + midIndex + "的位置!");
stepButton.Text = "開始";
targetText.Enabled = true;
}
This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.