Capture mouse when control is visible

  • Thread starter Thread starter Ron Vecchi
  • Start date Start date
R

Ron Vecchi

I need to allow my control when it is visible to capture the mouse and not
let any other control react to mouse events until control is hidden.

Similar to ContextMenu

Any Suggestions
 
Ron,

You can call the SetCapture API function through the P/Invoke layer to
do this. The declaration is as follows:

[DllImport("user32.dll")]
public static extern IntPtr SetCapture(IntPtr hWnd);

Hope this helps.
 
Thanks,

I was hoping to stay away from unmanaged code is there another way through
the framework or am I pretty much stuck with P/Invoke.


Ron

Nicholas Paldino said:
Ron,

You can call the SetCapture API function through the P/Invoke layer to
do this. The declaration is as follows:

[DllImport("user32.dll")]
public static extern IntPtr SetCapture(IntPtr hWnd);

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ron Vecchi said:
I need to allow my control when it is visible to capture the mouse and not
let any other control react to mouse events until control is hidden.

Similar to ContextMenu

Any Suggestions
 
Hi Ron,

In your "not let any other control react to mouse events", what does your
"other control" refer to?
If it refers only to the controls in the same form, I think you can
intercept all the Mouse message to the form and pass it to your certain
control.

If it refers to all the forms in windows, I think the only way is through
SetCapture method.

Anyway, I recommand you P/inovke SetCapture.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Ron,

Do you still have any concern on this issue?
Actually, .Net did not include all the feature of windows.
So it introduces the P/invoke technical to supplement it. Many platform
related issue should be completed through P/invoke.(Such as Hook technical,
Memory Mapping File, etc)
Through P/invoke, you can invoke the win32 APIs of windows.

For more information about P/invoke, please refer to the article below:
http://msdn.microsoft.com/msdnmag/issues/03/07/NET/

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thanks Jeffrey,

Since my menu control is basically for my own personal use I decided to
create my own form inhertied from System.windows.Form
The form will interact with the menu control to provide the nesessary
functionality.

I want to stay away from P/Invoke so I can use the controls with MONO.

Thanks
 
Hi Ron,

Oh, I see your concern, but the .Net class library still did not included
this feature of classes, so I think it can only be done through the support
of specifical platform.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top