By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,816 Members | 2,053 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,816 IT Pros & Developers. It's quick & easy.

Sending events to parent form even when a dialogue is open

P: 24
Hello guys

I have some custom events in my application i.e. KeyPress such as full screen for pressing F11 and so on. Currently this works fine but only when the main form which is listening tot he KayPress events. I would like this to work even when a Dialogue window is open from this form for example I am opening a child window with Show.Dialogue(). This is blocking the events from going to the parent form.

Can someone please put me in the right direction or give some hints on this.

Thanks in advance.
Dec 31 '08 #1
Share this Question
Share on Google+
8 Replies

P: 24
sorry guys I was meant to type:


in my above post. This is what I am using to show the form as a dialog.

Dec 31 '08 #2

Expert 5K+
P: 7,872
Well the point of a dialog is to force users to only be able to interact with THAT form, otherwise you would just use .Show()

You could consider capturing events on that Dialog and then pipe them back to the parent window.
Dec 31 '08 #3

P: 24
This sounds okay to me, but how would I send the same event back tot he paren form? i.e. lets say I have this KeyDown event of F11 how would I send it back to parent form when the Dialog is open?

help appreciated.
Dec 31 '08 #4

Expert 5K+
P: 7,872
In your case it might be rather easy.
Attach an event handler to the dialog form in the parent form.

Something like:
Expand|Select|Wrap|Line Numbers
  1. mydialogform d = new mydialogform();
  2. d.KeyPress+=new KeyPressEventHandler(d_KeyPress);
  3. d.ShowDialog();
Then in your d_keypress function you can perform the same checks for F11(and etc)

Actually, you might be able to RE-USE the same keypress event handler you have for the parent form, by also attaching it to dialogform.
Dec 31 '08 #5

P: 24

I know this an old post, but rather than creating a new thread I think its better to extend this one as the question is relted to the above subject as well.

The above mentioned method to pipe through the KeyPress events to the Parent works like a charm, but it gets rather painful when there are a lot of Dialogue forms in the application. I was wondering if there is a way to capture events globally within the application, such that the keypress events are also forwarded to the Parent form. Reason for having such a global control is that I will be having Dialogues generated by the Dialogues of the Parent form i.e. Dialogue in another layer of Dialogue like a grand child. It makes the events piping a little messy as I would have to attach listner for each instance.

I have searched this forum for an answer to my question but I could only find something that is related to global events listner from CodeProject:

I think it only send events to the application as a whole which means the events will go to the currently active Dialgue/Form and the parent Form in this case may not be the active Form. So is there any solution to my problem?
Apr 22 '09 #6

Expert 5K+
P: 7,872
You could try using "global hooks":

You would not need to attach event handlers everywhere then
Apr 22 '09 #7

P: 24
Thanks a lot,

Sorry I posted before testing the application, the project on CodeProject does provide the solution to my problem.

Apr 22 '09 #8

P: 24

I have been thinking of finding a slightly different way of finding a way to send those KeyDown events to the parent Form rather than using that "global hooks" mecahnism from codeproject:

I tried to create a custom events using Delegate, and crated and listener for it in the parent Form, a method to invoke the event is created in the sub child Form or any other Form. When the event is knvoked I can see that the Parent Form can listen to the event, I am also able to send KeyPressArgs in the events to find which key was pressed.

However this custom event I build will be resideing in a Static class, so that it is visible to all Forms in the application. I was wondering if this is a good way to go about my problem? as in it wouldn't effect or create a new problem for me? I would very much appreciate your view on this, as I do not have a lot of experience with C#.

Apr 27 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.