invoking child window keyup event in an mdi application

  • Thread starter Thread starter CJack
  • Start date Start date
C

CJack

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, System.EventArgs e)
{
MessageBox.Show("keyboard button pressed!");
}
Following is the code to load the frmTestBaby

private void menuItem2_Click(object sender, System.EventArgs e)
{
frmTBaby frmTestBaby = new frmTBaby();
frmTestBaby.MdiParent = this;
frmTestBaby.Show();
}

Can someone help out to how to get the event raised KeyUp for the
child form frmTestBaby.
Please note that I have also tried activating the
child
form after
frmTestBaby.Show(); but it did not work.

regards
 
Tie into the KeyUp event on your parent form where you create your child window. Something like this should work:

private void Button_Click(object sender, EventArgs e)
{
frmTBaby baby = new frmTBaby();
baby.KeyUp += new frmTBaby.KeyEventHandler(myMethod);
baby.Show();
}

private void myMethod(object sender, KeyEventArgs kea)
{
MessageBox.Show("A key was pressed in the frmTBaby form.");
}

Hope this helps.

-Nick Parker
 
Sorry, my initial post does not work correctly. I wasn't sitting with VS.NET in front of me. While the idea compiles it throws a System.ArgumentException. I'm interested to see how the solution will play out. Good luck

-Nick Parker
 
Ok, after I walked away I realized that I was typing something different than what you were asking, the following will work (sorry, I've had a long day). The basic idea is that you are tying into the KeyUp event which holds a series of delegates in a linked-list fashion. Here is the example

private void button_click(object sender, EventArgs e

// Create an instance of your frmTBaby object
frmTBaby baby = new frmTBaby()

// Assign the parent..
baby..MdiParent = this

// Assign your method you want to be called, note th
// signature of the method, it is important. We are basically
// registering your "myMethod" function with the KeyUp event here
baby.KeyUp += new System.Windows.Forms.KeyEventHandler(myMethod)

// show the form
baby.Show()


private void myMethod(object sender, KeyEventArgs kea

MessageBox.Show("I get displayed when someone lets the key up on frmTBaby")



Hope this helps

-Nick Parke
 
Back
Top