Tutorial :Trap mouse clicks outside of modal dialog



Question:

I have an application written in C# targeting .NET Compact Framework 3.5, running on Windows CE. I would like to provide a custom visual cue in a modal dialog if the user tries to interact with its owner window without closing the dialog first.

Is it possible for a modal dialog to receive notifications of mouse clicks on its owner window? The owner window is running in full screen, so it would be sufficient to trap clicks outside of the modal dialog in general.


Solution:1

This is how modality works. When a dialog is shown modally (CE or desktop Windows) that window gets it's own internal message pump. What that means is that wehn you get a message (like a mouse down) outside of your Window, the pump discards it. There's no way for the pump to dispatch that message "up" the chain to another pump (well not without you mucking with both pumps yourself - it's possible yes, but complex, convoluted, and not at all scalable or maintainable).


Solution:2

You could probably use the Control.Capture property.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »