繁体   English   中英

将Exe嵌入Winform C#应用程序:鼠标单击在菜单栏和工具栏上不起作用

[英]Embed Exe in Winform c# application: Mouse click not working on menustrip and toolstrip

我使用Menustrip和Toolstrip在VS 2010中创建了一个简单的Winform C#应用程序(.exe)。

现在,我使用以下代码将此应用程序嵌入到另一个Winform应用程序中。

问题是我无法在嵌入式应用程序中单击MenuItem或Toolstrip按钮。 Alt + F或键盘快捷键在起作用,但菜单或工具栏项上没有鼠标单击。 谢谢您的回复。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Process p = Process.Start("C:\\NewFolder\\myapplication.exe");
        Thread.Sleep(500); // Allow the process to open it's window
        SetParent(p.MainWindowHandle, panel1.Handle);
    }

    [DllImport("user32.dll")]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
}
}

尝试使用

    p.WaitForInputIdle();

而不是

    Thread.Sleep(500);

在这里找到: 如何在我的C#程序面板中运行另一个应用程序? (包括更多有用的内容)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM