473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

events in parent and child

I have a form that declares new form and both are shown. When my parent
form has focus it handles events correctly using this function:

protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
{
switch(e.KeyCode)
{

case Keys.Escape:
this.Close();
break;
case Keys.P:
MessageBox.Show("debug");
p.LastName = "test";
break;
//default:
// break;
}
}

when I use this function from my child form, nothing happens (i thought
it would automatically be called just as the parent form did).
What am i missing?

Nov 16 '05 #1
3 1610
I looked a little deeper into my problem and saw that as soon as I add
any control to my form, my "protected override void OnKeyDown" method
stops getting picked up. any reason why this happens?

Nov 16 '05 #2
The controls you have added are getting the keystrokes before the form does,
and if they handle the keystroke, then the form will not see it.

You can try setting the form's KeyPreview property to "true". Or, if it's
command keys you want to handle, you may be better off overriding
ProcessCmdKey, something like this:
protected override bool ProcessCmdKey(ref Message msg,Keys keyData)
{
// If the "current gridview" property is assigned, then all
// Up/Down arrows should navigate the grid
if ( gvCurrent == null )
{
return base.ProcessCmdKey(ref msg, keyData);
}
if ( gvCurrent.GridControl.Enabled == false )
{
return base.ProcessCmdKey(ref msg, keyData);
}
switch (keyData)
{
case Keys.Up:
gvCurrent.MovePrev();
return true;
case Keys.Down:
gvCurrent.MoveNext();
return true;
case Keys.PageUp:
gvCurrent.MovePrevPage();
return true;
case Keys.PageDown:
gvCurrent.MoveNextPage();
return true;
default:
return base.ProcessCmdKey(ref msg, keyData);
}
}

"vidalsasoon" <kj*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I looked a little deeper into my problem and saw that as soon as I add
any control to my form, my "protected override void OnKeyDown" method
stops getting picked up. any reason why this happens?

Nov 16 '05 #3
setting "KeyPreview = true" worked like a charm. thx

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
8
by: CJack | last post by:
hy, I have an mdi application, i create a child form and I want to know when a button is pressed while that child form is loaded. I have this code: private void frmTestBaby_KeyUp(object sender,...
4
by: Sean Connery | last post by:
I know I can merge a child forms menu into the MDI parent's mainmenu, but I would also like to listen for common events fired from the mainmenu that might be of interest to any child forms. Is...
3
by: Kenton Smeltzer | last post by:
Hello All, I am having a problem with events and the addition of controls on a page I am developing. First let me tell you what I have tried and then maybe someone can see something I missed. ...
1
by: Peter Rilling | last post by:
I have an interesting problem with a datagrid. It is the standard chicken-and-the-egg problem. I have this page with two datagrids. It essentially defines a parent-child relationship. The...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
3
by: Franky | last post by:
IN vb.Net Class clsCommande Inherits CollectionBase and Class clsProduct clsCommand contain a IList of clsProduct
7
by: Gene Vital | last post by:
Hi all, I need some help in understanding how to use Generics. I have a class based on a user control that can be put on any Container at runtime, I want to be able to call a method on the...
0
by: uupi_duu | last post by:
Hello, I have a parent class which creates and uses child class. Child class use it's own methods for different tasks. If an error occurs in child classes methods I would like to inform it to...
4
by: Harlequin | last post by:
I have a question concerning the need to trigger events within a "child" subform which is itself enbedded within a master "parent" form and which is accessible via a tab in the parent form. Becuase...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.