title: Click a button programmatically C#
body: <p>I am looking for a way to click a button programmatically (Winform). I have a form (say Form2) and button (Button2) of my project. When I click my button it should click Button1 (which is in another project), but both are in same solution.
      This is what I tried to do:</p>
  
  <pre><code>private void button2(object sender, EventArgs e)
  {
  
      System.IntPtr hwnd;
  
      System.IntPtr hwndChild = IntPtr.Zero;
  
      hwnd = FindWindow(null, "form1");
  
      if (hwnd.Equals(IntPtr.Zero))
      {
       MessageBox.Show("Couldn't find the form");
      }
      else
      {
      hwndChild = FindWindowEx((IntPtr)hwnd, IntPtr.Zero, null, "BUTTON1");
  
      if(!hwndChild.Equals(IntPtr.Zero))
      SendMessage(hwndChild, BM_CLICK, IntPtr.Zero, IntPtr.Zero);
      }
  }
  </code></pre>
  
  <p>Should I use any other approach like reflection instead of this?</p>
  
  <p>P.S: Button1 is private and no changes can be made to that function/project</p>