1

我想在图像上做一个 if 语句

          if (SortName.Image == Properties.Resources.RadioEmpty)
          {
              SortName.Image = Properties.Resources.Radio;
          }
          else
          {
              SortName.Image = Properties.Resources.RadioEmpty;
          }

但它在工作任何想法我做错了什么?好的附加信息

1.

          //SortName = A picture box
          //Properties.Resources.RadioEmpty = Resources\RadioEmpty.png
          //Properties.Resources.Radio = Resources\Radio.png

2.不,没有错误

3.我想为单选按钮使用自定义图像。A有一个带有上述代码的图片框点击。RadioEmpty 是默认设置,所以我检查图片框的图像是否与资源文件夹中的图像相同,代码也是如此。

4

3 回答 3

4

我建议您为此问题使用标签,请参阅此代码

  private void Form1_Load(object sender, EventArgs e)
        {
            //in form load the radio is checked or unckecked
            //here my radio is unchecked at load
            pictureBox1.Image = WindowsFormsApplication5.Properties.Resources.Add;
            pictureBox1.Tag = "UnChecked";
        }

   private void pictureBox1_Click(object sender, EventArgs e)
        {
            //after pictiurebox clicked change the image and tag too
            if (pictureBox1.Tag.ToString() == "Checked")
            {
                pictureBox1.Image = WinFormsApplication.Properties.Resources.Add;
                pictureBox1.Tag = "UnChecked";
            }
            else
            {
                pictureBox1.Image = WinFormsApplication.Properties.Resources.Delete;
                pictureBox1.Tag = "Checked";
            }
        }
于 2012-05-06T06:03:09.783 回答
2

比较名字。像这样的东西(未验证)

if (SortName.Image.Name.Equals(Properties.Resources.RadioEmpty.Name))
于 2012-05-06T05:10:06.263 回答
0
 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Bitmap bm1;
        Bitmap bm2;
        private void button1_Click(object sender, EventArgs e)
        {
            bm1 = new Bitmap(Properties.Resources.firegirl1);
            bm2 = new Bitmap(Properties.Resources.Zemli2);
            pictureBox1.Image = bm1;
            pictureBox2.Image = bm2;
            if (pictureBox1.Image==pictureBox2.Image)
            {
                MessageBox.Show("Some");
            }
            else
            {
                MessageBox.Show("Differ");
            }
        }
}
于 2014-04-21T19:59:23.983 回答