我對使用winform應用程序執行以下操作感興趣,我打算在Visual Studio 2010 IDE的c#文件夾中打開一個.exe文件。在WinForm項目選項卡中運行exe文件
我目前能夠通過點擊按鈕在使用下面的代碼所需的選項卡打開程序:
string str = @"-INSERT FILEPATH HERE-";//took file path out as i have a few exes i'm wanting to add.
Process process = new Process();
process.StartInfo.FileName = str;
process.Start();
現在我怎樣才能使它所以這個可執行文件打開的選項卡或選項卡,在我的winform?我願意接受任何案例的建議。
解決:
using System.Runtime.InteropServices;
using System.Threading;
[DllImport("user32.dll", SetLastError = true)]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
public GUI()
{
// Initialize form fieds
InitializeComponent();
openProgram()
}
private void openProgram()
{
process.StartInfo.FileName = "-filepathhere-";
process.Start();
IntPtr ptr = IntPtr.Zero;
while ((ptr = process.MainWindowHandle) == IntPtr.Zero) ;
SetParent(process.MainWindowHandle, trackerPanel.Handle);
MoveWindow(process.MainWindowHandle, 0, 0, this.Width - 90, this.Height, true);
}
你的意思是在'winforms'使用'TabControl'? – spajce 2013-03-13 18:56:48
是的,我希望它作爲選項卡在選項卡控件中。 – PhoenixLament 2013-03-13 23:53:52
所以你試圖打開TabControl中的記事本,你可以嘗試爲該任務使用'richTextBox'。 – spajce 2013-03-13 23:57:07