samedi 18 juillet 2020

More than one condition in C#

I'm having trouble in C# my code has to detect that every pictureBox has same image then do a process. But my code is not running properly. I'm using .Net Framework 4.8 and WinForms.

Event: Button1_Click

Code:

            string Location = Application.StartupPath.ToString();
            if (pictureBox1.BackgroundImage == Properties.Resources.tick &
                pictureBox2.BackgroundImage == Properties.Resources.tick &
                pictureBox3.BackgroundImage == Properties.Resources.tick &
                pictureBox4.BackgroundImage == Properties.Resources.tick &
                pictureBox5.BackgroundImage == Properties.Resources.tick)
            {
                if (File.Exists(Location + "\\files\\e.etf"))
                {
                    File.Delete(Location + "\\files\\e.etf");
                }
                if (File.Exists(Location + "\\files\\n.etf"))
                {
                    File.Delete(Location + "\\files\\n.etf");
                }
                if (File.Exists(Location + "\\files\\p.etf"))
                {
                    File.Delete(Location + "\\files\\p.etf");
                }

            }
            else
            {
                MessageBox.Show("Error");
            }

But whenever I click the button it always shows the MessageBox showing "Error". Please help me. Thank you in advanced. 🙂

Aucun commentaire:

Enregistrer un commentaire