title: how to change background of a form on a value returning from serial
body: <p>I'm new to c#,i have been trying to change the color of form when I receive a value from a serial, I am using event handling method to receive data from serial monitor, yet the output is not coming. I have here by attached the code.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.IO.Ports;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  namespace WindowsFormsApplication1
  {
      public partial class Form1 : Form
      {
          SerialPort port;
  
         public delegate void UpdateGUI(string str);
         public void DisplayReceivedData(string str)
         {
             string ja = "12";
            //listBox1.Items.Add("received");
           //  if(StringComparison
              listBox1.Items.Add(str);
              textBox1.Text = ja;
              int test = String.Compare(str, ja);
              textBox1.Text =Convert.ToString(str);
              if (test == 0)
              {
                  ActiveForm.BackColor = System.Drawing.Color.DarkBlue;
              }
              else
              {
                  ActiveForm.BackColor = System.Drawing.Color.White;
              }
  
          }
          public void Datareceived(object sender, SerialDataReceivedEventArgs arg)
          {
              SerialPort sp = (SerialPort)sender;
              string str = sp.ReadExisting();
              Invoke(new UpdateGUI(DisplayReceivedData),str);
  
          } 
          public Form1()
          {
              InitializeComponent();
          }
  
          private void Form1_Load(object sender, EventArgs e)
          {
              port = new SerialPort("COM10");
              port.BaudRate = 9600;
              port.Parity = Parity.None;
              port.StopBits = StopBits.One;
              port.DataBits = 8;
              port.Handshake = Handshake.None;
              port.RtsEnable = true;
              port.DataReceived += new SerialDataReceivedEventHandler(Datareceived);
              port.Open();
          }
  
  
          private void button1_Click(object sender, EventArgs e)
          {
              ActiveForm.BackColor = System.Drawing.Color.DarkBlue;
          }
  
          private void button2_Click(object sender, EventArgs e)
          {
              ActiveForm.BackColor = System.Drawing.Color.White;
  
          }
  
          private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
          {
  
          }
  
      }
  }
  </code></pre>