1

I want to do an if stament on an image

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

but its on working any idea what I'm doing wrong ? o.k additional information

1.

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

2. Nope no errors

3.I wanted to use a custom image for a radio button. A have a picture box with the above code on click. RadioEmpty is the default so I check to see if the picturebox's image is the same as image form the Resources folder is so do code.

4

3 に答える 3

4

i advise you use tag for this issue see this code

  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

compare the names. Something like this (unverified)

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 に答える