title: Winform showing another application inside a PictureBox
body: <p>First, I would like to state that I understand that my problem is similar to <a href="https://stackoverflow.com/questions/12006392/running-another-application-inside-a-picturebox">Running another application inside a picturebox</a>, however my application runs the .exe just fine it instead will not always nest it inside the picturebox.</p>
  
  <p>In my c# winforms application I am attempting to run the calc.exe inside a PictureBox, however about 75% of the time my application just runs the calc.exe as its own window.</p>
  
  <p>My code is below.</p>
  
  <pre><code>enter code hereprivate void Preview_Button_Click(object sender, EventArgs e)
      {
          if (ActiveWindows_ListBox.SelectedItem == null)
          {
              MessageBox.Show("There is no Window selected to take a picture of.", "Insufficient Data");
              return;
          }
          Process p = Process.Start("calc.exe");
          Thread.Sleep(500);
          p.WaitForInputIdle();
          SetParent(p.MainWindowHandle, ViewingScreen_PictureBox.Handle);
      }
  </code></pre>
  
  <p>From my understanding of what I am trying to do I am starting the  calc.exe application that is native to windows, then telling my application to wait for the calculator to initialize its self then tell the calculator that the picturebox is the parent of the calculator. </p>
  
  <p>That leaves my question, is there something that I am missing which is making it so that my application doesn't set the calculator inside the picturebox 100% of the time?</p>
  
  <p>Thank you for the help in advance. </p>
  
  <p>P.S. I have tried to adjust the Thread.Sleep to give my application more and less time than what it has now with no change in behavior.</p>