Alt键和选项卡在从WPF应用程序打开的Windows窗体中不起作用 [英] Alt keys and tab don't work in Windows Forms opened from a WPF application
问题描述
我有很多旧的Windows Forms应用程序,这些应用程序最终将移植到WPF(这是一个大型应用程序,因此无法一次完成),并且我已经通过在WPF中创建一个主菜单开始了该过程. Windows窗体应用程序是从此菜单打开的单独窗口.
I have lots of old Windows Forms applications that will eventually be ported to WPF (it is a large application so it can't be done in one sprint), and I have started the process by creating a main menu in WPF. The Windows Forms applications are separate windows opened from this menu.
Windows窗体应用程序正在打开并且可以正常运行,除了,快捷键和 Tab 键存在的问题. Tab键不会将焦点移到下一个控件,并且 Alt 键触发& Search按钮不再起作用.
The Windows Forms applications 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.
我在做什么错了?
推荐答案
我终于设法通过将Winform托管在WPF表单的WindowsFormsHost控件中来解决此问题.
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应用程序打开的Windows窗体中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!