---
title: "C# check button image"  
description: "C# check button image"  
author: "Anonymous User"  
published: 2014-02-04  
updated: 2014-02-04  
canonical: https://www.mindstick.com/forum/1949/c-sharp-check-button-image  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# C# check button image

I need to [check if](https://www.mindstick.com/forum/12878/how-to-check-if-an-asp-dot-net-file-upload-control-has-a-file-in-jquery) the [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) have no [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character)(BackColor changes to [green](https://www.mindstick.com/articles/95829/think-green-sustainable-design-considerations-for-commercial-buildings)) or an image called Atorre(BackColor changes to [red](https://yourviews.mindstick.com/view/81343/lonar-lake-turning-red-again)), heres my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):

```
public static bool IsEnemyOrEmptyA(Button check){    var Atorre = teste.Properties.Resources.Atorre;    bool res;    if (check == null || check.Image == null)    {        res = true;        check.BackColor = Color.Green;        return res;    }    else if (check.Image == teste.Properties.Resources.Atorre)    {        res = true;        check.BackColor = Color.Red;        return res;    }    else    {        res = false;        return res;    }}
```

but even if its an other image, the button displays backcolor red or nothing. Any [suggestions](https://www.mindstick.com/blog/299486/how-to-write-for-your-audience)?

## Replies

### Reply by Pravesh Singh

Hi Ankit,\

This is the only way to compare images, you shouldn't be comparing images but instead compare some variables.

```
   private void button1_Click(object sender, EventArgs e)    {        var Atorre = Resource1.test;        var DifferentImage = Resource1.test2;        byte[] a = BitmapToBytes(Atorre);        byte[] b = BitmapToBytes(DifferentImage);        bool isEqual = true;        if (a.Length == b.Length && a != null && b != null)        {            for (int i = 0; i < b.Length; i++)  //compare every byte            {                if (b[i] != a[i])                {                    isEqual = false;                    break;                }            }        }        else        {            isEqual = false;        }        if(isEqual)            MessageBox.Show("It's EQUAL");        else            MessageBox.Show("Not EQUAL");}    //Convert Image to Bytes    public static byte[] BitmapToBytes(Bitmap Bitmap)    {        System.IO.MemoryStream ms = null;        try        {            ms = new System.IO.MemoryStream();            Bitmap.Save(ms, Bitmap.RawFormat);            byte[] byteImage = new Byte[ms.Length];            byteImage = ms.ToArray();            return byteImage;        }        catch (ArgumentNullException ex)        {            throw ex;        }        finally        {            ms.Close();        }    }
```

\


---

Original Source: https://www.mindstick.com/forum/1949/c-sharp-check-button-image

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
