How to trigger key press event of a child from from Mdi Form

C

CV

Hi,

How can we trigger key press event of a child from from Mdi Form

Please Suggst.

Thanks & REgards
CV
 
C

ClayB [Syncfusion]

One way you can do this is to derive the child form class. In your derived
class, add a public member, MyKeyPress, that accepts a keypresseventargs
variable. In this public method, call the protected OnKeyPress method
passing the arg. Then this public MyKeyPress method can be called from
anywhere the form object is known. (I think you can also use reflection to
access protected members, but exposing a public member in a derived class is
probably more straight-forward if you can derive the class.)


====================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
G

Guest

H

Add a handler to the Keypress event of the Child form in your mdi form when you declare and instantiate the child form

In MDI Form [VB]

Dim Child as Form = New Custome
AddHandler Child.KeyPress, AddressOf HandleChildKeyPres

Public Sub HandleChildKeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs
'Code for handling the Key press of child For
End Su

Sooraj P
Microsoft India Communit Star
 
G

Guest

H

My opinion is it will be better to use AddHandler in MDIform rather than going for a Base and dervied classes

Sooraj P
Microsoft India Community Star
 
C

ClayB [Syncfusion]

I may be wrong, but I am not sure adding a handler will "trigger" a
keypress.

A handler will react to a key that is pressed by the user, but how do tell a
handler to press the letter 'a', and have all the listeners to the KeyPress
event catch this action?

If you want to 'fire' the KeyPress event so all listeners can catch it, then
I think you will need to somehow call the protected OnKeyPress method of the
class.

======================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools


Sooraj PM said:
Hi

My opinion is it will be better to use AddHandler in MDIform rather than
going for a Base and dervied classes.
 
G

Guest

H

This was the solution I passed in my earlier mail. The argument e of HandleChildKeyPress procedure can be used to detect which key user has pressed

Sooraj P
Microsoft India Community Sta

Add a handler to the Keypress event of the Child form in your mdi form when you declare and instantiate the child form

In MDI Form [VB]

Dim Child as Form = New Custome
AddHandler Child.KeyPress, AddressOf HandleChildKeyPres

Public Sub HandleChildKeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs
'Code for handling the Key press of child For
End Su


----- ClayB [Syncfusion] wrote: ----

I may be wrong, but I am not sure adding a handler will "trigger"
keypress

A handler will react to a key that is pressed by the user, but how do tell
handler to press the letter 'a', and have all the listeners to the KeyPres
event catch this action

If you want to 'fire' the KeyPress event so all listeners can catch it, the
I think you will need to somehow call the protected OnKeyPress method of th
class

=====================
Clay Burch, .NET MV

Visit www.syncfusion.com for the coolest tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top