weixin_44138934
wxy新人小白
2019-11-14 23:47
采纳率: 73.7%
浏览 770

在C#中如何点击按钮可更换pictureBox里的图片

在C#中在textbox上输入一个数,点击按钮,根据数的范围,更换pictureBox里的图片
图片说明

private void button1_Click(object sender, EventArgs e)
        {
            int ts = Convert.ToInt32(txttanshang.Text);
            if (0<ts<120)
            {
                pictureBox1.BackgroundImage = WindowsFormsApplication2.Properties.Resources.BG1;
                pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
            }
            else if (120 <= ts < 240)
            {
                pictureBox1.BackgroundImage = WindowsFormsApplication2.Properties.Resources.BG1;
                pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
            }
            else if (240 <= ts < 360)
            {
                pictureBox1.BackgroundImage = WindowsFormsApplication2.Properties.Resources.BG1;
                pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
            }
            else if (360 <= ts)
            {
                pictureBox1.BackgroundImage = WindowsFormsApplication2.Properties.Resources.BG1;
                pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
            }

        }

如何处理 if (0<ts<120)处显示小于号无法处理bool和int类的操作

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • caozhy
    已采纳
     if (0<ts<120)
    不能这么写
    应该是
     if (0<ts  && ts<120)
    
    点赞 评论

相关推荐