Keyboard shortcuts not working when adding a form to a C # panel

I am writing an application where I have a form with a panel. I noticed that when I add another form to the panel, the hotkeys of the added form 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 work with keyboard shortcuts?

Hello

0


a source to share


3 answers


I found out it was related to focus issues.



Since then, I've converted my forms to custom controls and the problems went away.

0


a source


My first guess (and this is entirely a guess) is that you need to pass the parent / owner when creating the child, not just assign the parent ... could you show us this part of your code?



Also, just by looking at your code, it seems strange, for MainMenu, set the Dock to fill ....

+1


a source


Adding a form to a panel inside another form? This is not a supported scenario; to be honest, I'm surprised this is no exception. The best way to do this is using UserControls.

0


a source







All Articles