ALT键和选项卡不从WPF应用程序打开的WinForms工作 [英] Alt keys and tab don't work in winforms opened from a WPF application

查看:320
本文介绍了ALT键和选项卡不从WPF应用程序打开的WinForms工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多老的WinForms的最终将被移植到WPF(它是一个大的应用程序,因此它不能在一个冲刺完成),我已经通过创建一个WPF主菜单启动过程中。在的WinForms从这个菜单中打开不同的窗口。

I have lots of old winforms that will eventually be ported to WPF (it is a large app so it can't be done in one sprint), and I have started the process by creating a main menu in WPF. The winforms are separate windows opened from this menu.

的WinForms被打开,工作不我与快捷有任何问题的除了问题和Tab键。 TAB键不移动焦点到下一个控制和Alt键来触发&放大器;搜索按钮不再适用

The winforms are opening and working without any problems except the issues I am having with the shortcut and tab keys. The tab key is not moving focus to the next control, and the alt key to trigger the &Search button no longer works.

谁能告诉我,我在做什么错了?

Can anyone tell me what I am doing wrong?

谢谢! < 333

Thanks!!! <333

推荐答案

我终于设法通过举办一个WPF表单内WindowsFormsHost控件内部的winform来解决该问题

I finally managed to fix the issue by hosting the winform inside a WindowsFormsHost control inside a WPF form.

public partial class MyWindow : Window
{
    public MyWindow()
    {
        InitializeComponent();

        Form winform = new Form();
        // to embed a winform using windowsFormsHost, you need to explicitly
        // tell the form it is not the top level control or you will get
        // a runtime error.
        winform.TopLevel = false;

        // hide border because it will already have the WPF window border
        winform.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        this.windowsFormsHost.Child = winform;
    }

}

请注意,您可能还需要如果你有一个按钮来关闭窗体挂钩在WinForm关闭事件。

Please note that you may also need to hook up the winform close event if you have a button to close the form.

这篇关于ALT键和选项卡不从WPF应用程序打开的WinForms工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆