title: Detecting a color when it appears on screen
body: <p>I wanted to make a color detection program to display a message box when a certain color is found</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Security.AccessControl;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  
  namespace evade
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
          private void button1_Click(object sender, EventArgs e)
          {
  
              SearchPixel("#00042");
  
          }
  
          private bool SearchPixel(string hexcode)
          {
              Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
              Graphics graphics = Graphics.FromImage(bitmap as Image);
              graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
  
              Color desiredPixelColor = ColorTranslator.FromHtml(hexcode);
  
              while (true)
              {
  
                  for (int x = 0; x &lt; SystemInformation.VirtualScreen.Width; x++)
                  {
                      for (int y = 0; x &lt; SystemInformation.VirtualScreen.Height; y++)
                      {
                          Color currentPixelColor = bitmap.GetPixel(x, y);
  
  
                          if (desiredPixelColor == currentPixelColor)
                          {
  
                              MessageBox.Show("Found!");
                              return true;
  
                          }
  
                          else
                          {
                              return false;
                          }
                      }
  
  
  
                  }
  
              }
  
          }
  
  
      }
  }
  </code></pre>
  
  <p>So that's my code. And the color is #00042 this one (html) I'm running the detection on a while loop so when the desired color appears on screen it displays a little message box but It does not work.</p>