C#
--
Questions
--
Followers
Top Experts
I need to catch, for example, a Ctrl+A key press on a form.
Usually I set the KeyPreview to true and handle the KeyDown Event... no problem.
Now I need to do this on an MDIChild form but the KeyDown event just doesn't fire.
Although it does fire on the MDI Parent.
Is there a way to work this out?
Thanks,
Alex
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
That is not an option on my scenario.
This MDIParent holds 16 different projects that have an overall of 1000+ Forms...
It's not "doable" to hadle each case on the MDIParent...
Although that gave me a great idea...
I can create and Interface, implement it on the child forms, validate on the MDIParent KeyDown Event if there's an active MDIChild and if so if it also implements my Interface then finally if everything is true, call the method on the MDI Active Child.
Great!!
Thanks for putting my head to work...
Alex
1) Parent has KeyPreview = True
2) Child has KeyPreview = True
3) Child Form_KeyPress:
private void OnFormKeyPress(object sender, System.Windows.Forms.KeyPr
{
this.textBox1.AppendText(e
e.Handled = true;
}
4) Parent Form_KeyPress:
private void OnFormKeyPress(object sender, System.Windows.Forms.KeyPr
{
MessageBox.Show(e.KeyChar)
}
5) Without the e.Handled = true in the child handler, the message would flow up to the parent, and I would get a message box. With it I don't.
Bob






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
I tried that but couldn't reproduce the behavior you said.
I tried some combinations with the KeyPreview set to true and false between MDI parent and child and nothing.
If I use the KeyPressEvent instead of the KeyDown I lose some informations on the eventargs and still the parent gets called.
It gets called before the child form...
Can you describe the configurations you use the get that behavior?
Thanks!
Alex
Thanks Bob... that worked but... :)
They came with some new ideas...
We use MenuStrips on both child and parent, and assign shortcut keys to them.
If the same shortcut exists on both parent and child, the child event will never raise...
Any ideas?!
Many thanks!
Alex
Bob

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Scenario:
1- Create 2 Forms, one MDIParent and one MDIChild
2- Add a MenuStrip to both
3- Add one MenuItem on both
4- Set the same ShortcutKey on both MenuItems (use the ShortcutKey property on the Menu item)
5- Add a messagebox to the MenuItemsClick so you can identify whitch was called
Test:
Having both forms visible (MDIParent with the MDIChild on it), try to use the shortcut key to trigger the MDIChild MenuItem.
Result:
The MDIParent is the one that allways gets called!!
Thanks!
Alex
That is a significantly more difficult proposition. I haven't found a solution yet.
Bob
The MDI structure itself is very limitted...
I think this is one more thing that is just no ment to be done.
As this is a Fox upgrade, we had some other things that had to be left behind an dsome others that we had to do strange
|stupid things to accomplish (some good examples are simply desable tab pages... and a lot of stuff related to the DataGridView).
Many thanks Bob,
Alex






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
private void TestToolStripMenuItem_Clic
{
int shortCutValue = (int)((ToolStripMenuItem)s
if (this.ActiveMdiChild != null)
{
foreach (Control ctl in this.ActiveMdiChild.Contro
{
if (ctl.GetType() == typeof(MenuStrip))
{
MenuStrip strip = (MenuStrip)ctl;
foreach (ToolStripItem item in strip.Items)
{
if (item.GetType() == typeof(ToolStripMenuItem) && ((int)((ToolStripMenuItem)
{
return;
}
}
}
}
}
MessageBox.Show("Main form");
}
Bob
I haven't found any solution yet.
C#
--
Questions
--
Followers
Top Experts
C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).