简体   繁体   English

WinForms和WPF UserControl显示另一个窗口

[英]WinForms with WPF UserControl which shows another window

I have a problem with input interoperation in WinForms and WPF. 我在WinForms和WPF中的输入互操作有问题。

Winforms/C#: Winforms / C#:

UserControlDLL.MyUserControl userControl = new UserControlDLL.MyUserControl();

public Form1()
{
    InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
    userControl.ShowTextBox();
}

WPF: WPF:

public partial class MyUserControl : UserControl
{
    internal static DisplayWindow display;

    public MyUserControl()
    {
        InitializeComponent();
        display = new DisplayWindow();
    }
}

When userControl creates the new DisplayWindow I can't enter anything in the textbox on the DisplayWindow. 当userControl创建新的DisplayWindow时,我无法在DisplayWindow的文本框中输入任何内容。

Try this : 试试这个

public Form1()
{
    InitializeComponent();

    ElementHost host= new ElementHost();
    host.Size = new Size(200, 100);
    host.Location = new Point(100,100);

    UserControlDLL.MyUserControl edit = new UserControlDLL.MyUserControl();
    host.Child = edit;

    this.Controls.Add(host);
}

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

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