Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 0.92 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to open process within Windows form
  2. [DllImport("user32.dll", SetLastError = true)]
  3.         static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
  4.        private void button1_Click(object sender, EventArgs e)
  5.     {
  6.         Process p = Process.Start("mstsc.exe", @"c:VPN4.rdp");
  7.         Thread.Sleep(3000);
  8.         p.StartInfo.CreateNoWindow = true;    // new
  9.         SetParent(p.MainWindowHandle, this.panel1.Handle);
  10.         p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;   //new
  11.  
  12.     }
  13.        
  14. private void toolStripButton1_Click(object sender, EventArgs e)
  15. {
  16.   ProcessStartInfo info = new ProcessStartInfo();
  17.   info.FileName = "notepad";
  18.   info.UseShellExecute = true;
  19.   var process = Process.Start(info);
  20.  
  21.   Thread.Sleep(2000);
  22.  
  23.   SetParent(process.MainWindowHandle, this.Handle);
  24. }
  25.        
  26. ProcessStartInfo info = new ProcessStartInfo();
  27. info.FileName = "notepad";
  28. info.UseShellExecute = true;
  29. Process.Start(info);