469,643 Members | 1,655 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

MDI Child form events .... could not be raised :(

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
Nov 15 '05 #1
8 4583
Hi,

If I understand you correctly, you want to raise an event
from the child form so the parent form can receive the
event. If that's what you want, here's what you can try.

1. Add the event handler to the frmTestParent form:

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

frmTestBaby.KeyUp += new
System.Windows.Forms.KeyEventHandler
(this.frmTestBaby_KeyUp);
}

2. Add the code to the frmTestParent form to handle the
event.

private void frmTestBaby_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
MessageBox("Event Receive from Parent: KeyUp was "
e.KeyCode);
}

This will only work if the frmTestBaby form does not have
a control (ie: text box) that will receive the KeyUp
event before the form. Otherwise, the control has to
raise the event so the form will receive it.

Hope this helps,
Thomas

Disclaimer:
This posting is provided "AS IS" with no warranties, and
confers no rights. "Use of included script samples are
subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"
-----Original Message-----
hy,
I have an mdi application, i create a child form and I want to knowwhen 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 thechild form frmTestBaby.
Please note that I have also tried activating the child form afterfrmTestBaby.Show(); but it did not work.

regards
.

Nov 15 '05 #2
Thanks Thomas, I tried the code but still it did not work :( any other
idea please share with me

"Thomas Ha [MSFT]" <th*@online.microsoft.com> wrote in message news:<05****************************@phx.gbl>...
Hi,

If I understand you correctly, you want to raise an event
from the child form so the parent form can receive the
event. If that's what you want, here's what you can try.

1. Add the event handler to the frmTestParent form:

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

frmTestBaby.KeyUp += new
System.Windows.Forms.KeyEventHandler
(this.frmTestBaby_KeyUp);
}

2. Add the code to the frmTestParent form to handle the
event.

private void frmTestBaby_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
MessageBox("Event Receive from Parent: KeyUp was "
e.KeyCode);
}

This will only work if the frmTestBaby form does not have
a control (ie: text box) that will receive the KeyUp
event before the form. Otherwise, the control has to
raise the event so the form will receive it.

Hope this helps,
Thomas

Disclaimer:
This posting is provided "AS IS" with no warranties, and
confers no rights. "Use of included script samples are
subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"
-----Original Message-----
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
.

Nov 15 '05 #3
You have to make sure the controls inside frmTestBaby
form do not receive the KeyUp event first. This may not
be possible. Also, clicking on the button does not raise
a KeyUp event.

I read your original question again. If you just want
the parent to receive an event when the child form is
loaded, you should have the parent capture the
frmTestBaby.Load event instead of the KeyUp event.

Try the following code:

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

private void frmTestBaby_Load(object sender,
System.EventArgs e)
{
MessageBox.Show("child form loaded");
}

Please let me know if I've misunderstood your question
again. I hope this will point you to the right path.

Thomas

Disclaimer:
This posting is provided "AS IS" with no warranties, and
confers no rights. "Use of included script samples are
subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

-----Original Message-----
Thanks Thomas, I tried the code but still it did not work :( any otheridea please share with me

"Thomas Ha [MSFT]" <th*@online.microsoft.com> wrote in

message news:<05****************************@phx.gbl>...
Hi,

If I understand you correctly, you want to raise an event from the child form so the parent form can receive the
event. If that's what you want, here's what you can try.
1. Add the event handler to the frmTestParent form:

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

frmTestBaby.KeyUp += new
System.Windows.Forms.KeyEventHandler
(this.frmTestBaby_KeyUp);
}

2. Add the code to the frmTestParent form to handle the event.

private void frmTestBaby_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
MessageBox("Event Receive from Parent: KeyUp was " e.KeyCode);
}

This will only work if the frmTestBaby form does not have a control (ie: text box) that will receive the KeyUp
event before the form. Otherwise, the control has to
raise the event so the form will receive it.

Hope this helps,
Thomas

Disclaimer:
This posting is provided "AS IS" with no warranties, and confers no rights. "Use of included script samples are
subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"
>-----Original Message-----
>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
>.
>

.

Nov 15 '05 #4
<<< I need to raise event on child form keyup >>>.
my code is not working that i mentioned in first post. I also tried ur
approach for the parent form to recieve the event keyup and raise it,
this is also not working. just to check for events in child forms, i
tried to define a mouse click event on the child form, it is perfectly
working.
I dnt understand that why keyup event is not working on child form of
an mdi application. is it a limitation on c#?
could u plz help.
regards
Arif
"Thomas Ha [MSFT]" <th*@online.microsoft.com> wrote in message news:<02****************************@phx.gbl>...
You have to make sure the controls inside frmTestBaby
form do not receive the KeyUp event first. This may not
be possible. Also, clicking on the button does not raise
a KeyUp event.

I read your original question again. If you just want
the parent to receive an event when the child form is
loaded, you should have the parent capture the
frmTestBaby.Load event instead of the KeyUp event.

Try the following code:

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

private void frmTestBaby_Load(object sender,
System.EventArgs e)
{
MessageBox.Show("child form loaded");
}

Please let me know if I've misunderstood your question
again. I hope this will point you to the right path.

Thomas

Disclaimer:
This posting is provided "AS IS" with no warranties, and
confers no rights. "Use of included script samples are
subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

-----Original Message-----
Thanks Thomas, I tried the code but still it did not

work :( any other
idea please share with me

"Thomas Ha [MSFT]" <th*@online.microsoft.com> wrote in

message news:<05****************************@phx.gbl>...
Hi,

If I understand you correctly, you want to raise an event from the child form so the parent form can receive the
event. If that's what you want, here's what you can try.
1. Add the event handler to the frmTestParent form:

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

frmTestBaby.KeyUp += new
System.Windows.Forms.KeyEventHandler
(this.frmTestBaby_KeyUp);
}

2. Add the code to the frmTestParent form to handle the event.

private void frmTestBaby_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
MessageBox("Event Receive from Parent: KeyUp was " e.KeyCode);
}

This will only work if the frmTestBaby form does not have a control (ie: text box) that will receive the KeyUp
event before the form. Otherwise, the control has to
raise the event so the form will receive it.

Hope this helps,
Thomas

Disclaimer:
This posting is provided "AS IS" with no warranties, and confers no rights. "Use of included script samples are
subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

>-----Original Message-----
>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
>.
>

.

Nov 15 '05 #5
Hi Arif,

Sorry, I totally misunderstood what you were trying to
do. All you wanted to do was to detect a KeyUp event in
the frmBabyTest whenever a key is pressed on any controls
inside the frmBabyTest form, correct?

As I mentioned in my first response, the controls inside
the frmBabyTest form will receive the KeyUp event first.
As a result, the frmBabyTest never receives it.
Therefore, the control, that receives the KeyUp event,
needs to raise it to the frmBabyTest form.

For example:

private void TextBox1_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
MessageBox.Show("From TextBox1_KeyUp");
this.OnKeyUp(e); // Raise the onKeyUp event
}

private void frmBabyTest_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
MessageBox.Show("from frmBabyTest_KeyUp");
}

Don't forget to add this to the InitializeComponent() or
frmBabyTest constructor:

this.KeyUp += new System.Windows.Forms.KeyEventHandler
(this. frmBabyTest_KeyUp);

This will work. I tested it out on my test MDI app.
Thomas

Disclaimer:
This posting is provided "AS IS" with no warranties, and
confers no rights. "Use of included script samples are
subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"



-----Original Message-----
<<< I need to raise event on child form keyup >>>.
my code is not working that i mentioned in first post. I also tried urapproach for the parent form to recieve the event keyup and raise it,this is also not working. just to check for events in child forms, itried to define a mouse click event on the child form, it is perfectlyworking.
I dnt understand that why keyup event is not working on child form ofan mdi application. is it a limitation on c#?
could u plz help.
regards
Arif
"Thomas Ha [MSFT]" <th*@online.microsoft.com> wrote in

message news:<02****************************@phx.gbl>...
You have to make sure the controls inside frmTestBaby
form do not receive the KeyUp event first. This may not be possible. Also, clicking on the button does not raise a KeyUp event.

I read your original question again. If you just want
the parent to receive an event when the child form is
loaded, you should have the parent capture the
frmTestBaby.Load event instead of the KeyUp event.

Try the following code:

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

private void frmTestBaby_Load(object sender,
System.EventArgs e)
{
MessageBox.Show("child form loaded");
}

Please let me know if I've misunderstood your question
again. I hope this will point you to the right path.

Thomas

Disclaimer:
This posting is provided "AS IS" with no warranties, and confers no rights. "Use of included script samples are
subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

>-----Original Message-----
>Thanks Thomas, I tried the code but still it did not

work :( any other
>idea please share with me
>
>"Thomas Ha [MSFT]" <th*@online.microsoft.com> wrote in
message news:<056b01c3bacc$50eefc40 $a*******@phx.gbl>... >> Hi,
>>
>> If I understand you correctly, you want to raise an

event
>> from the child form so the parent form can receive the >> event. If that's what you want, here's what you can try.
>>
>> 1. Add the event handler to the frmTestParent form:
>>
>> private void menuItem2_Click(object sender,
>> System.EventArgs e)
>> {
>> frmTBaby frmTestBaby = new frmTBaby();
>> frmTestBaby.MdiParent = this;
>> frmTestBaby.Show();
>>
>> frmTestBaby.KeyUp += new
>> System.Windows.Forms.KeyEventHandler
>> (this.frmTestBaby_KeyUp);
>> }
>>
>> 2. Add the code to the frmTestParent form to handle

the
>> event.
>>
>> private void frmTestBaby_KeyUp(object sender,
>> System.Windows.Forms.KeyEventArgs e)
>> {
>> MessageBox("Event Receive from Parent: KeyUp

was "
>> e.KeyCode);
>> }
>>
>> This will only work if the frmTestBaby form does
not have
>> a control (ie: text box) that will receive the
KeyUp >> event before the form. Otherwise, the control has to >> raise the event so the form will receive it.
>>
>> Hope this helps,
>> Thomas
>>
>> Disclaimer:
>> This posting is provided "AS IS" with no warranties, and
>> confers no rights. "Use of included script samples
are >> subject to the terms specified at
>> http://www.microsoft.com/info/cpyright.htm"
>>
>>
>>
>> >-----Original Message-----
>> >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
>> >.
>> >
>.
>

.

Nov 15 '05 #6
hy Thomas, I think that I could not communicate well. I neeed to raise
KeyUp event OF the CHILD Form. For example if the child form name is
frmBaby then I need to have some action on
frmBaby_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
MessageBox.Show("Key up on child form frmBaby");
}
I DO NOT want to raise events on the controls of child form now.
can you tell me how to do this? or can you guide me if i could find
some documents detailing this or in worse case if C# is able to handle
child form events?

i hope you know what i mean.
regards

"Thomas Ha" <th*@online.microsoft.com> wrote in message news:<02****************************@phx.gbl>...
Hi Arif,

Sorry, I totally misunderstood what you were trying to
do. All you wanted to do was to detect a KeyUp event in
the frmBabyTest whenever a key is pressed on any controls
inside the frmBabyTest form, correct?

As I mentioned in my first response, the controls inside
the frmBabyTest form will receive the KeyUp event first.
As a result, the frmBabyTest never receives it.
Therefore, the control, that receives the KeyUp event,
needs to raise it to the frmBabyTest form.

For example:

private void TextBox1_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
MessageBox.Show("From TextBox1_KeyUp");
this.OnKeyUp(e); // Raise the onKeyUp event
}

private void frmBabyTest_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
MessageBox.Show("from frmBabyTest_KeyUp");
}

Don't forget to add this to the InitializeComponent() or
frmBabyTest constructor:

this.KeyUp += new System.Windows.Forms.KeyEventHandler
(this. frmBabyTest_KeyUp);

This will work. I tested it out on my test MDI app.
Thomas

Disclaimer:
This posting is provided "AS IS" with no warranties, and
confers no rights. "Use of included script samples are
subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"



-----Original Message-----
<<< I need to raise event on child form keyup >>>.
my code is not working that i mentioned in first post. I

also tried ur
approach for the parent form to recieve the event keyup

and raise it,
this is also not working. just to check for events in

child forms, i
tried to define a mouse click event on the child form,

it is perfectly
working.
I dnt understand that why keyup event is not working on

child form of
an mdi application. is it a limitation on c#?
could u plz help.
regards
Arif
"Thomas Ha [MSFT]" <th*@online.microsoft.com> wrote in

message news:<02****************************@phx.gbl>...
You have to make sure the controls inside frmTestBaby
form do not receive the KeyUp event first. This may not be possible. Also, clicking on the button does not raise a KeyUp event.

I read your original question again. If you just want
the parent to receive an event when the child form is
loaded, you should have the parent capture the
frmTestBaby.Load event instead of the KeyUp event.

Try the following code:

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

private void frmTestBaby_Load(object sender,
System.EventArgs e)
{
MessageBox.Show("child form loaded");
}

Please let me know if I've misunderstood your question
again. I hope this will point you to the right path.

Thomas

Disclaimer:
This posting is provided "AS IS" with no warranties, and confers no rights. "Use of included script samples are
subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"
>-----Original Message-----
>Thanks Thomas, I tried the code but still it did not work :( any other >idea please share with me
>
>"Thomas Ha [MSFT]" <th*@online.microsoft.com> wrote in message news:<056b01c3bacc$50eefc40 $a*******@phx.gbl>... >> Hi,
>>
>> If I understand you correctly, you want to raise an event >> from the child form so the parent form can receive the >> event. If that's what you want, here's what you can
try. >>
>> 1. Add the event handler to the frmTestParent form:
>>
>> private void menuItem2_Click(object sender,
>> System.EventArgs e)
>> {
>> frmTBaby frmTestBaby = new frmTBaby();
>> frmTestBaby.MdiParent = this;
>> frmTestBaby.Show();
>>
>> frmTestBaby.KeyUp += new
>> System.Windows.Forms.KeyEventHandler
>> (this.frmTestBaby_KeyUp);
>> }
>>
>> 2. Add the code to the frmTestParent form to handle the >> event.
>>
>> private void frmTestBaby_KeyUp(object sender,
>> System.Windows.Forms.KeyEventArgs e)
>> {
>> MessageBox("Event Receive from Parent: KeyUp was " >> e.KeyCode);
>> }
>>
>> This will only work if the frmTestBaby form does not
have >> a control (ie: text box) that will receive the KeyUp >> event before the form. Otherwise, the control has to >> raise the event so the form will receive it.
>>
>> Hope this helps,
>> Thomas
>>
>> Disclaimer:
>> This posting is provided "AS IS" with no warranties,
and >> confers no rights. "Use of included script samples are >> subject to the terms specified at
>> http://www.microsoft.com/info/cpyright.htm"
>>
>>
>>
>> >-----Original Message-----
>> >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
>> >.
>> >
>.
>

.

Nov 15 '05 #7
Hi Arif,

I understand that's what you want. The last sample does
exactly what you want. You need to understand that if
your frmBaby has any controls (which it does), the
controls will receive the KeyUp event first if any are in
focus. Therefore your frmBaby never receive the event.
That's why each of your controls need to raise the KeyUp
event (frmBaby.KeyUp(e)) so the frmBaby will receive it.

You mentioned earlier that the click event works fine.
That's because you can click on an area of the form where
no controls are located. As a result, the frmBaby
receives the onclick event first instead of any controls.

Here's a test you can do. Remove all of your controls or
disable all of them in the frmBaby. Then capture the
KeyUp event in the frmBaby, you'll find out that it will
work without raising a KeyUp event from any controls.

Hope this will clarify the issue!
Thomas

Disclaimer:
This posting is provided "AS IS" with no warranties, and
confers no rights. "Use of included script samples are
subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

-----Original Message-----
hy Thomas, I think that I could not communicate well. I neeed to raiseKeyUp event OF the CHILD Form. For example if the child form name isfrmBaby then I need to have some action on
frmBaby_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e){
MessageBox.Show("Key up on child form frmBaby");
}
I DO NOT want to raise events on the controls of child form now.can you tell me how to do this? or can you guide me if i could findsome documents detailing this or in worse case if C# is able to handlechild form events?

i hope you know what i mean.
regards

"Thomas Ha" <th*@online.microsoft.com> wrote in message

news:<02****************************@phx.gbl>...
Hi Arif,

Sorry, I totally misunderstood what you were trying to
do. All you wanted to do was to detect a KeyUp event in the frmBabyTest whenever a key is pressed on any controls inside the frmBabyTest form, correct?

As I mentioned in my first response, the controls inside the frmBabyTest form will receive the KeyUp event first. As a result, the frmBabyTest never receives it.
Therefore, the control, that receives the KeyUp event,
needs to raise it to the frmBabyTest form.

For example:

private void TextBox1_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
MessageBox.Show("From TextBox1_KeyUp");
this.OnKeyUp(e); // Raise the onKeyUp event
}

private void frmBabyTest_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
MessageBox.Show("from frmBabyTest_KeyUp");
}

Don't forget to add this to the InitializeComponent() or frmBabyTest constructor:

this.KeyUp += new System.Windows.Forms.KeyEventHandler
(this. frmBabyTest_KeyUp);

This will work. I tested it out on my test MDI app.
Thomas

Disclaimer:
This posting is provided "AS IS" with no warranties, and confers no rights. "Use of included script samples are
subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"



>-----Original Message-----
><<< I need to raise event on child form keyup >>>.
>my code is not working that i mentioned in first post. I
also tried ur
>approach for the parent form to recieve the event
keyup and raise it,
>this is also not working. just to check for events in

child forms, i
>tried to define a mouse click event on the child
form, it is perfectly
>working.
>I dnt understand that why keyup event is not working
on child form of
>an mdi application. is it a limitation on c#?
>could u plz help.
>regards
>Arif
>"Thomas Ha [MSFT]" <th*@online.microsoft.com> wrote
in message news:<02ca01c3bb62$2c13cc70 $a*******@phx.gbl>... >> You have to make sure the controls inside frmTestBaby >> form do not receive the KeyUp event first. This may not
>> be possible. Also, clicking on the button does not

raise
>> a KeyUp event.
>>
>> I read your original question again. If you just
want >> the parent to receive an event when the child form is >> loaded, you should have the parent capture the
>> frmTestBaby.Load event instead of the KeyUp event.
>>
>> Try the following code:
>>
>> private void menuItem2_Click(object sender,
>> System.EventArgs e)
>> {
>> frmTBaby frmTestBaby = new frmTBaby();
>> frmTestBaby.Load += new System.EventHandler
>> (this.frmTestBaby_Load);
>> frmTestBaby.MdiParent = this;
>> frmTestBaby.Show();
>> }
>>
>> private void frmTestBaby_Load(object sender,
>> System.EventArgs e)
>> {
>> MessageBox.Show("child form loaded");
>> }
>>
>> Please let me know if I've misunderstood your question >> again. I hope this will point you to the right path. >>
>> Thomas
>>
>> Disclaimer:
>> This posting is provided "AS IS" with no warranties, and
>> confers no rights. "Use of included script samples
are >> subject to the terms specified at
>> http://www.microsoft.com/info/cpyright.htm"
>>
>>
>> >-----Original Message-----
>> >Thanks Thomas, I tried the code but still it did not work :( any other
>> >idea please share with me
>> >
>> >"Thomas Ha [MSFT]" <th*@online.microsoft.com>
wrote in
>> message news:<056b01c3bacc$50eefc40

$a*******@phx.gbl>...
>> >> Hi,
>> >>
>> >> If I understand you correctly, you want to raise
an event
>> >> from the child form so the parent form can
receive the
>> >> event. If that's what you want, here's what you

can
try.
>> >>
>> >> 1. Add the event handler to the frmTestParent
form: >> >>
>> >> private void menuItem2_Click(object sender,
>> >> System.EventArgs e)
>> >> {
>> >> frmTBaby frmTestBaby = new frmTBaby();
>> >> frmTestBaby.MdiParent = this;
>> >> frmTestBaby.Show();
>> >>
>> >> frmTestBaby.KeyUp += new
>> >> System.Windows.Forms.KeyEventHandler
>> >> (this.frmTestBaby_KeyUp);
>> >> }
>> >>
>> >> 2. Add the code to the frmTestParent form to handle the
>> >> event.
>> >>
>> >> private void frmTestBaby_KeyUp(object sender,
>> >> System.Windows.Forms.KeyEventArgs e)
>> >> {
>> >> MessageBox("Event Receive from Parent:
KeyUp was "
>> >> e.KeyCode);
>> >> }
>> >>
>> >> This will only work if the frmTestBaby form does

not
have
>> >> a control (ie: text box) that will receive the

KeyUp
>> >> event before the form. Otherwise, the control
has to
>> >> raise the event so the form will receive it.
>> >>
>> >> Hope this helps,
>> >> Thomas
>> >>
>> >> Disclaimer:
>> >> This posting is provided "AS IS" with no

warranties,
and
>> >> confers no rights. "Use of included script
samples are
>> >> subject to the terms specified at
>> >> http://www.microsoft.com/info/cpyright.htm"
>> >>
>> >>
>> >>
>> >> >-----Original Message-----
>> >> >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
>> >> >.
>> >> >
>> >.
>> >
>.
>

.

Nov 15 '05 #8
Thank you very much Thomas. Its working now.

"Thomas Ha [MSFT]" <th*@online.microsoft.com> wrote in message news:<10*****************************@phx.gbl>...
Hi Arif,

I understand that's what you want. The last sample does
exactly what you want. You need to understand that if
your frmBaby has any controls (which it does), the
controls will receive the KeyUp event first if any are in
focus. Therefore your frmBaby never receive the event.
That's why each of your controls need to raise the KeyUp
event (frmBaby.KeyUp(e)) so the frmBaby will receive it.

You mentioned earlier that the click event works fine.
That's because you can click on an area of the form where
no controls are located. As a result, the frmBaby
receives the onclick event first instead of any controls.

Here's a test you can do. Remove all of your controls or
disable all of them in the frmBaby. Then capture the
KeyUp event in the frmBaby, you'll find out that it will
work without raising a KeyUp event from any controls.

Hope this will clarify the issue!
Thomas

Disclaimer:
This posting is provided "AS IS" with no warranties, and
confers no rights. "Use of included script samples are
subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

-----Original Message-----
hy Thomas, I think that I could not communicate well. I

neeed to raise
KeyUp event OF the CHILD Form. For example if the child

form name is
frmBaby then I need to have some action on
frmBaby_KeyUp(object sender,

System.Windows.Forms.KeyEventArgs e)
{
MessageBox.Show("Key up on child form frmBaby");
}
I DO NOT want to raise events on the controls of child

form now.
can you tell me how to do this? or can you guide me if i

could find
some documents detailing this or in worse case if C# is

able to handle
child form events?

i hope you know what i mean.
regards

"Thomas Ha" <th*@online.microsoft.com> wrote in message

news:<02****************************@phx.gbl>...
Hi Arif,

Sorry, I totally misunderstood what you were trying to
do. All you wanted to do was to detect a KeyUp event in the frmBabyTest whenever a key is pressed on any controls inside the frmBabyTest form, correct?

As I mentioned in my first response, the controls inside the frmBabyTest form will receive the KeyUp event first. As a result, the frmBabyTest never receives it.
Therefore, the control, that receives the KeyUp event,
needs to raise it to the frmBabyTest form.

For example:

private void TextBox1_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
MessageBox.Show("From TextBox1_KeyUp");
this.OnKeyUp(e); // Raise the onKeyUp event
}

private void frmBabyTest_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
MessageBox.Show("from frmBabyTest_KeyUp");
}

Don't forget to add this to the InitializeComponent() or frmBabyTest constructor:

this.KeyUp += new System.Windows.Forms.KeyEventHandler
(this. frmBabyTest_KeyUp);

This will work. I tested it out on my test MDI app.
Thomas

Disclaimer:
This posting is provided "AS IS" with no warranties, and confers no rights. "Use of included script samples are
subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"


>-----Original Message-----
><<< I need to raise event on child form keyup >>>.
>my code is not working that i mentioned in first post. I
also tried ur >approach for the parent form to recieve the event keyup
and raise it, >this is also not working. just to check for events in child forms, i >tried to define a mouse click event on the child form,
it is perfectly >working.
>I dnt understand that why keyup event is not working on
child form of >an mdi application. is it a limitation on c#?
>could u plz help.
>regards
>Arif
>"Thomas Ha [MSFT]" <th*@online.microsoft.com> wrote in message news:<02ca01c3bb62$2c13cc70 $a*******@phx.gbl>... >> You have to make sure the controls inside frmTestBaby >> form do not receive the KeyUp event first. This may
not >> be possible. Also, clicking on the button does not raise >> a KeyUp event.
>>
>> I read your original question again. If you just want >> the parent to receive an event when the child form is >> loaded, you should have the parent capture the
>> frmTestBaby.Load event instead of the KeyUp event.
>>
>> Try the following code:
>>
>> private void menuItem2_Click(object sender,
>> System.EventArgs e)
>> {
>> frmTBaby frmTestBaby = new frmTBaby();
>> frmTestBaby.Load += new System.EventHandler
>> (this.frmTestBaby_Load);
>> frmTestBaby.MdiParent = this;
>> frmTestBaby.Show();
>> }
>>
>> private void frmTestBaby_Load(object sender,
>> System.EventArgs e)
>> {
>> MessageBox.Show("child form loaded");
>> }
>>
>> Please let me know if I've misunderstood your question >> again. I hope this will point you to the right path. >>
>> Thomas
>>
>> Disclaimer:
>> This posting is provided "AS IS" with no warranties,
and >> confers no rights. "Use of included script samples are >> subject to the terms specified at
>> http://www.microsoft.com/info/cpyright.htm"
>>
>>
>> >-----Original Message-----
>> >Thanks Thomas, I tried the code but still it did not
work :( any other >> >idea please share with me
>> >
>> >"Thomas Ha [MSFT]" <th*@online.microsoft.com> wrote
in >> message news:<056b01c3bacc$50eefc40 $a*******@phx.gbl>... >> >> Hi,
>> >>
>> >> If I understand you correctly, you want to raise an
event >> >> from the child form so the parent form can receive
the >> >> event. If that's what you want, here's what you
can
try.
>> >>
>> >> 1. Add the event handler to the frmTestParent form: >> >>
>> >> private void menuItem2_Click(object sender,
>> >> System.EventArgs e)
>> >> {
>> >> frmTBaby frmTestBaby = new frmTBaby();
>> >> frmTestBaby.MdiParent = this;
>> >> frmTestBaby.Show();
>> >>
>> >> frmTestBaby.KeyUp += new
>> >> System.Windows.Forms.KeyEventHandler
>> >> (this.frmTestBaby_KeyUp);
>> >> }
>> >>
>> >> 2. Add the code to the frmTestParent form to handle
the >> >> event.
>> >>
>> >> private void frmTestBaby_KeyUp(object sender,
>> >> System.Windows.Forms.KeyEventArgs e)
>> >> {
>> >> MessageBox("Event Receive from Parent: KeyUp
was " >> >> e.KeyCode);
>> >> }
>> >>
>> >> This will only work if the frmTestBaby form does
not
have
>> >> a control (ie: text box) that will receive the KeyUp >> >> event before the form. Otherwise, the control has
to >> >> raise the event so the form will receive it.
>> >>
>> >> Hope this helps,
>> >> Thomas
>> >>
>> >> Disclaimer:
>> >> This posting is provided "AS IS" with no
warranties,
and
>> >> confers no rights. "Use of included script samples
are >> >> subject to the terms specified at
>> >> http://www.microsoft.com/info/cpyright.htm"
>> >>
>> >>
>> >>
>> >> >-----Original Message-----
>> >> >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
>> >> >.
>> >> >
>> >.
>> >
>.
>

.

Nov 15 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Frank T. Clark | last post: by
1 post views Thread by Martin Douglas | last post: by
1 post views Thread by al | last post: by
7 posts views Thread by Darin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.