Hi Tyler,
I'm afraid you need do it by your self, Window message will always first
route to the parent window, it's by design.
Thanks!
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!
--------------------
| From: "Tyler" <
[email protected]>
| References: <#
[email protected]>
<
[email protected]>
| Subject: Re: MDI Form and KeyUp Event
| Date: Wed, 15 Oct 2003 09:02:07 -0400
| Lines: 208
| 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.framework.windowsforms
| NNTP-Posting-Host: g252.lweb.net 209.167.237.252
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:54484
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Thank-you,
|
| When I set the KeyPreview property, I now receive the keypress events.
The
| only problem I have using the KeyPreview is that it gives the MDI
container
| form the keystroke before any of the child windows receive it.
|
| Ideally, I would like to have the MDI container get the keystroke if none
of
| its MDI child windows handle the keypress. Is there a nice/simple way to
do
| this, or must I write some special code to make my MDI container and child
| windows interoperate to determine who handles the keypress? For example,
I
| could set KeyPreview to true and capture the KeyUp event in my MDI
| container. Then I could always invoke a custom public method of my MDI
| container's active MDI child to determine whether it wanted to handle the
| keypress. I would work, but it does not seem as clean as it could be.
|
| Thanks, Tyler
|
|
| | > Hi Tyler,
| > I think probably you forgot to set the KeyPreview property of the main
| form.
| > Here is my test code, you wil see the message in the KeyUp events in the
| > output box of VS.NET.
| > Please be free to let me know if you have anything unclear on this
issue.
| > <code>
| > using System;
| > using System.Drawing;
| > using System.Collections;
| > using System.ComponentModel;
| > using System.Windows.Forms;
| > using System.Data;
| >
| > namespace WinForm_MDI_KeyEvent
| > {
| > /// <summary>
| > /// Summary description for Form1.
| > /// </summary>
| > public class Form1 : System.Windows.Forms.Form
| > {
| > private System.Windows.Forms.MainMenu mainMenu1;
| > private System.Windows.Forms.MenuItem menuItem1;
| > private System.Windows.Forms.MenuItem menuItem2;
| > /// <summary>
| > /// Required designer variable.
| > /// </summary>
| > private System.ComponentModel.Container components = null;
| >
| > public Form1()
| > {
| > //
| > // Required for Windows Form Designer support
| > //
| > InitializeComponent();
| >
| > //
| > // TODO: Add any constructor code after InitializeComponent call
| > //
| > }
| >
| > /// <summary>
| > /// Clean up any resources being used.
| > /// </summary>
| > protected override void Dispose( bool disposing )
| > {
| > if( disposing )
| > {
| > if (components != null)
| > {
| > components.Dispose();
| > }
| > }
| > base.Dispose( disposing );
| > }
| >
| > #region Windows Form Designer generated code
| > /// <summary>
| > /// Required method for Designer support - do not modify
| > /// the contents of this method with the code editor.
| > /// </summary>
| > private void InitializeComponent()
| > {
| > this.mainMenu1 = new System.Windows.Forms.MainMenu();
| > this.menuItem1 = new System.Windows.Forms.MenuItem();
| > this.menuItem2 = new System.Windows.Forms.MenuItem();
| > //
| > // mainMenu1
| > //
| > this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
| > this.menuItem1});
| > //
| > // menuItem1
| > //
| > this.menuItem1.Index = 0;
| > this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
| > this.menuItem2});
| > this.menuItem1.Text = "File";
| > //
| > // menuItem2
| > //
| > this.menuItem2.Index = 0;
| > this.menuItem2.Text = "New";
| > this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
| > //
| > // Form1
| > //
| > this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
| > this.ClientSize = new System.Drawing.Size(292, 273);
| > this.IsMdiContainer = true;
| > this.KeyPreview = true;
| > this.Menu = this.mainMenu1;
| > this.Name = "Form1";
| > this.Text = "Form1";
| > this.KeyUp += new
System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp);
| >
| > }
| > #endregion
| >
| > /// <summary>
| > /// The main entry point for the application.
| > /// </summary>
| > [STAThread]
| > static void Main()
| > {
| > Application.Run(new Form1());
| > }
| >
| > private void Form1_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs
| > e)
| > {
| > System.Diagnostics.Debug.WriteLine("Key_Up");
| > }
| >
| > private void menuItem2_Click(object sender, System.EventArgs e)
| > {
| > ChildForm frm = new ChildForm();
| > frm.MdiParent = this;
| > frm.Show();
| > }
| >
| > private class ChildForm : System.Windows.Forms.Form
| > {
| > public ChildForm()
| > {
| > this.Text = "ChildForm";
| > this.KeyUp +=new KeyEventHandler(ChildForm_KeyUp);
| > }
| > private void ChildForm_KeyUp(object sender,
| > System.Windows.Forms.KeyEventArgs e)
| > {
| > System.Diagnostics.Debug.WriteLine("ChildForm_KeyUp");
| > }
| > }
| > }
| > }
| >
| > </code>
| >
| > Best regards,
| >
| > Ying-Shen Yu [MSFT]
| > Microsoft Online Partner Support
| > Get Secure! -
www.microsoft.com/security
| >
| > This posting is provided "AS IS" with no warranties and confers no
rights.
| > You should not reply this mail directly, "Online" should be removed
before
| > sending, Thanks!
| >
| > --------------------
| > | From: "Tyler" <
[email protected]>
| > | Subject: MDI Form and KeyUp Event
| > | Date: Tue, 14 Oct 2003 08:58:57 -0400
| > | Keywords: MDI KeyUp
| > | Lines: 12
| > | 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.framework.windowsforms
| > | NNTP-Posting-Host: g252.lweb.net 209.167.237.252
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| > microsoft.public.dotnet.framework.windowsforms:54393
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
| > |
| > | Is it possible to capture keypress events (KeyDown, KeyPress, KeyUp)
for
| > an
| > | MDI form? I have created a simple form where I only changed its name
| and
| > | its IsMdiContainer property (set to true). I added a handler for a
| KeyUp
| > | event, but the event is never fired?
| > |
| > | How can I capture keypresses that occur at this level? I want to be
| able
| > to
| > | watch for CTRL-V/SHIFT-INSERT combination to handle a user's request
to
| > | paste into my MDI window.
| > |
| > | Thanks, Tyler
| > |
| > |
| > |
| >
|
|
|