If picturebox.image == Properties.Resources.ImageA

后端 未结 2 1504
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-14 09:32

Im making few buttons(picturebox) that then you click them they change image.

I tryed this code but it always skips to else.

Images are loaded from resources

相关标签:
2条回答
  • 2021-01-14 09:47

    You should keep local reference to your resources, because when you invoke KaminuSkaiciuokle.Properties.Resources... you will always get new instance of object:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    
        Bitmap _icopalABitmap = KaminuSkaiciuokle.Properties.Resources.IcopalA;
        Bitmap _icopalBBitmap = KaminuSkaiciuokle.Properties.Resources.IcopalB;
    
        private void pictureBox1_Click(object sender, EventArgs e)
        {            
            if (pictureBox7.Image == _icopalABitmap)
            {
                pictureBox7.Image = _icopalBBitmap;
            }
            else
            {
                pictureBox7.Image = _icopalABitmap;
            }
        }
    
        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox7.Image = _icopalABitmap;
        }
    }
    
    0 讨论(0)
  • 2021-01-14 09:52

    please attention this code:

    Bitmap _icopalABitmap = KaminuSkaiciuokle.Properties.Resources.IcopalA;
    

    _icopalABitmap:it is name you ideal that. KaminuSkaiciuokle: it aqual your project name. IcopalA: is your picture name

    0 讨论(0)
提交回复
热议问题