title: How to set focus back to form after opening up a process (Notepad)?
body: <p>I open up a notepad from my program using <code>Process.Start()</code> but the new opened notepad covers the screen. But I do want my application to maintain its focus.</p>
  
  <p>I similarly (using the same Process.Start) open up MS Excel and Word but to get focus back to my form all I need to write is:</p>
  
  <pre><code>this.Focus();
  </code></pre>
  
  <p>But quirk with Notepad: I open notepad (and all other processes like this)</p>
  
  <pre><code>Process process = new Process();
  process.StartInfo.UseShellExecute = true;
  process.EnableRaisingEvents = true;
  process.StartInfo.FileName = @"abc.log";
  process.Start();
  </code></pre>
  
  <p>Now notepad takes the focus. </p>
  
  <p>I tried these:</p>
  
  <ol>
  <li><p><code>this.Activate()</code>, <code>this.Focus()</code>, needless to mention</p></li>
  <li><pre><code>[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]  
  public static extern IntPtr SetFocus(HandleRef hWnd);
  
  {
     IntPtr hWnd = myProcess.Handle;
     SetFocus(new HandleRef(null, hWnd));
  }
  </code></pre></li>
  <li><pre><code>[DllImport("User32")]
  private static extern int SetForegroundWindow(IntPtr hwnd);
  
  [DllImportAttribute("User32.DLL")]
  private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  private const int SW_SHOW = 5;
  private const int SW_MINIMIZE = 6;
  private const int SW_RESTORE = 9;
  
  {
      ShowWindow(Process.GetCurrentProcess().MainWindowHandle, SW_RESTORE);
      SetForegroundWindow(Process.GetCurrentProcess().MainWindowHandle);
  }
  </code></pre></li>
  <li><p>Another lengthier solution got from <a href="https://stackoverflow.com/questions/46030/c-sharp-force-form-focus">here</a>.</p></li>
  </ol>
  
  <p>All which still keeps the focus on notepad. Why is it so difficult to merely get focus to a window, that too application's own window?</p>
  
  <p>EDIT: At best I can open the notepad minimized, but it still wouldn't give the focus to the form after trying all the above codes. Notepad opens minimized, but focus will be still on notepad (something that sometimes we see in windows xp) and form will be out of focused.</p>