【发布时间】:2013-03-13 18:37:41
【问题描述】:
我有兴趣使用我正在编写的 winform 应用程序执行以下操作,以便在 Visual Studios 2010 IDE 中以 c# 格式在选项卡中打开 .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吗? -
是的,我希望它作为选项卡在选项卡控件中。
-
所以您尝试在 TabControl 中打开记事本,您可以尝试使用
richTextBox来完成该任务。 -
不是记事本,但是需要在 tabcontrol 中打开程序。
-
嗨@PhoenixLament,你自己的答案看起来很棒吗?您能否提供更多详细信息,我将代码粘贴到我的表单上,但出现与命名空间相关的错误。我已经导入了 user32.dll,但是和你一样,不能在面板内实例化任何应用程序。谢谢
标签: c# winforms process tabs exe