我试图从用户那里获取一个值,然后每次单击按钮它必须打印语句和代表多次尝试的图片。if 语句正在工作,但它总是显示最后一个案例的图片。
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
int gussednum= Convert.ToInt16( textBox1.Text);
for (int i = 0; i < 7; ++i)
{
if (interednum < num)
{
label1.Text = "Should be greater than" + num;
switch (i)
{
case (0) :
Image image = Image.FromFile("1.png");
pictureBox1.Image = image;
break;
case (1):
Image im2 = Image.FromFile("2.png");
pictureBox1.Image = im2;
break;
case (2):
Image im3 = Image.FromFile("3.png");
pictureBox1.Image = im3;
break;
case (3):
Image image4 = Image.FromFile("4.png");
pictureBox1.Image = image4;
break;
case (4):
Image image5 = Image.FromFile("5.png");
pictureBox1.Image = image5;
break;
case (5):
Image image6 = Image.FromFile("dead.gif");
pictureBox1.Image = image6;
break;
case (6):
Image image7 = Image.FromFile("red.png");
pictureBox1.Image = image7;
break;
}
}