Shortcut keys jump between forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm just starting to program with VB.NET 2003 on XP Pro SP1, and I've run
into what I think is some strange behavior. In the program I have a Main
form, which is MDIContainer. It then opens an MDIChild form, wich is a list
of names. The list form then opens an edit form to edit the name and sets it
as an MDIChid of Main using child.MDIParent = Me.ParentForm. Now we're
getting to the strange part: if both forms have the same shortcut key, let's
say Alt-E assigned to controls, pressing the shortcut repeatedly moves the
cursor from one form to the other, without activating the form. I could
accidentally be typing in the list form, although the editing form is the
active form.

Has anyone else run into this or have any idea how to prevent it from
happening?
 
I have seen behavior similar to this. We have an MDI application and the
mnemonic processing would check through all child windows even if they were
not active. This would result in the same sort of behavior you described.

The only way I was able to stop this was to create a subclass of
System.Windows.Forms.Form and override the ProcessMnemonic method:

protected override bool ProcessMnemonic(char charCode)
{
if( !this.ContainsFocus ) return false;
return base.ProcessMnemonic (charCode);
}

If there is a better way to solve this problem I'd love to know.

Rangi
 
Hi,

Thanks for the answer, and I apologize for not checking back sooner.

I've tried it on one form, and so far It seems to work. Now to copy the
code into the other 60-odd forms :)

Thank you.
 
Back
Top