将表单添加到面板时,键盘快捷键不起作用c#

时间:2021-01-23 15:54:49

I am writing an application where I have a form with a panel. I have noticed that when I add another form to the panel, that the added form's keyboard shortcuts stop working.

我正在编写一个应用程序,其中我有一个带有面板的表单。我注意到当我向面板添加另一个表单时,添加的表单的键盘快捷键停止工作。

I am using the following code :

我使用以下代码:

MainMenu m = new MainMenu();
m.TopLevel = false;
m.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
m.Dock = System.Windows.Forms.DockStyle.Fill;
pnl.Controls.Add(m);
m.Visible = true;
pnl.ResumeLayout();

Is there anyway to make the keyboard shortcuts work?

反正有没有使键盘快捷键工作?

Regards

3 个解决方案

#1


My first guess (and it's totally a guess) is that you need to pass the parent/owner when constructing the child object, rather than just assigning parent ... could you show us that part of your code?

我的第一个猜测(这完全是一个猜测)是你需要在构造子对象时传递父/所有者,而不仅仅是分配父...你能告诉我们你的代码的一部分吗?

Also, just glancing over your code, it seems strange to, for a MainMenu, set Dock to Fill....

另外,只是浏览你的代码,对于MainMenu来说,设置Dock to Fill似乎很奇怪....

#2


Adding a form to a panel inside another form? That is not a supported scenario; frankly I'm surprised it doesn't throw an exception. A better way to do this would be to use UserControls.

将表单添加到另一个表单内的面板?这不是一个支持的场景;坦率地说,我很惊讶它没有抛出异常。更好的方法是使用UserControls。

#3


I found out that it was due to focus issues.

我发现这是由于焦点问题。

I have since converted my forms to user controls and the problems have gone away.

我已经将表单转换为用户控件,问题已经消失。

#1


My first guess (and it's totally a guess) is that you need to pass the parent/owner when constructing the child object, rather than just assigning parent ... could you show us that part of your code?

我的第一个猜测(这完全是一个猜测)是你需要在构造子对象时传递父/所有者,而不仅仅是分配父...你能告诉我们你的代码的一部分吗?

Also, just glancing over your code, it seems strange to, for a MainMenu, set Dock to Fill....

另外,只是浏览你的代码,对于MainMenu来说,设置Dock to Fill似乎很奇怪....

#2


Adding a form to a panel inside another form? That is not a supported scenario; frankly I'm surprised it doesn't throw an exception. A better way to do this would be to use UserControls.

将表单添加到另一个表单内的面板?这不是一个支持的场景;坦率地说,我很惊讶它没有抛出异常。更好的方法是使用UserControls。

#3


I found out that it was due to focus issues.

我发现这是由于焦点问题。

I have since converted my forms to user controls and the problems have gone away.

我已经将表单转换为用户控件,问题已经消失。