473,379 Members | 1,423 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,379 software developers and data experts.

invoking child window keyup event in an mdi application

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
Jul 21 '05 #1
3 2046
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

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Jul 21 '05 #2
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

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Jul 21 '05 #3
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


---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Jul 21 '05 #4

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

Similar topics

2
by: Ron L | last post by:
I have an MDI application which opens a number of child windows, each of which could have data in a state that needs to be saved. Each child window catches its Closing event and cancels it if the...
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,...
2
by: CJack | last post by:
Hy. I have an MDI form Parent. on run-time it creates a child form Child1. when you press a keyboard button, the Control on Child1 recieves the KeyUp event, which raises the KeyUp event of Child1...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
2
by: Adam J. Schaff | last post by:
I have recently noticed an unwanted behavior that I do not know how to get rid of. To Recreate Problem: Windows Forms App with 2 forms. Form 1 has nothing on it and this code underneath: ...
0
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...
4
by: Steve Barnett | last post by:
I've created a simple MDI application and have designated the Window menu to keep track of the mdi children. When I first load an mdi child, it's caption consists of "File: no file loaded" and this...
12
by: Phil | last post by:
I can check for MdiChildren.Length=0, but which event handler should I put this in to detect when a child window is closed? TIA Phil.
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.