Hi Michael,
Just as the community said, the standard keyboard shortcut is suitable for
the users. (Ctrl+F4 for child form, Alt+F4 for parent form)
If you still want to use Alt+F4 to close all the child forms before closing
the parent form, you can hook the WM_SYSKEYDOWN message.
It seems that in MDI form, when you press Alt+F4, the WM_SYSKEYDOWN message
is sent to the current Active child form, but not the parent form.
So you should subclass all the child form's wndproc and handle its
WM_SYSKEYDOWN message.
In WM_SYSKEYDOWN message, you should close this child form then jump out of
this procedure.
Something like this:
public const int WM_SYSKEYDOWN = 0x104;
public const int VK_F4 = 0x73;
protected override void WndProc(ref Message m)
{
if(m.Msg==WM_SYSKEYDOWN)
{
if(m.WParam.ToInt32()==VK_F4)
{
MessageBox.Show("Alt+f4");
this.Close();
return;
}
}
base.WndProc (ref m);
}
It works well on my machine, If you have any unclear, please feel free to
let me know.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
| Reply-To: "Michael Maes" <
[email protected]>
| From: "Michael Maes" <
[email protected]>
| References: <
[email protected]>
<
[email protected]>
| Subject: Re: ALT+F4 in MDI-Applications
| Date: Tue, 14 Oct 2003 11:26:42 +0200
| Lines: 49
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <
[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: 204.54-136-217.adsl.skynet.be 217.136.54.204
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:146487
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Hi Eric,
|
| You could 'e.cancel' the 'closing-event' of the MDI-Form, but then you
face
| some problems:
| What if you want to close the MDI-Form (close-button, menu, esc, or even
| ALT+F4). (normally the user closes an application by closing the MDI, not
| explicitly closing all the children first)
| When you press ALT+F4 when a child has the focus, the event should happen
in
| the Childform, still the container closes. Does this mean the event is
| captured by the containrform and does it know where the request came from
| (sender). If that is the case you could cancel the event and close the
| "requesting" child.
|
| Michael
|
| | | you could cancel the close event in the mdi parent and close the active
| | child there
| | if there are no childs close the main form
| |
| | eric
| |
| | | | > Hello,
| | >
| | > ALT+F4 is the shortcut to close a form.
| | > When I use this shortcut in an MDI enviroment, the application is
| closed,
| | so
| | > obviously the shortcut applies to the 'Container' and not to the
| | > 'Childform'.
| | > What would be the best practice to capture this event and close the
| active
| | > child instead of the container (thus trying to end the application).
| | >
| | > --
| | > Thanks for helping,
| | >
| | > Michael Maes
| | >
| | > (I'm using vb.NET 2003 Enterprise Architect & SQL Server 2003 SP3)
| | >
| | >
| |
| |
|
|
|