browse: forums | FAQ
Connecting Tech Pros Worldwide

Hey there! Do you need C# / C Sharp help?

Get answers from our community of C# / C Sharp experts on BYTES! It's free.

Capture mouse when control is visible

Ron Vecchi
Guest
 
Posts: n/a
#1: Nov 15 '05
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 Vecchi






Nicholas Paldino [.NET/C# MVP]
Guest
 
Posts: n/a
#2: Nov 15 '05

re: Capture mouse when control is visible


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]
- mvp@spam.guard.caspershouse.com

"Ron Vecchi" <rvecchi@xilehdvecchi.com> wrote in message
news:u3CTh06yDHA.4060@TK2MSFTNGP11.phx.gbl...[color=blue]
> 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 Vecchi
>
>
>[/color]


Ron Vecchi
Guest
 
Posts: n/a
#3: Nov 15 '05

re: Capture mouse when control is visible


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 [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote in
message news:O3SRjv8yDHA.3436@tk2msftngp13.phx.gbl...[color=blue]
> 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]
> - mvp@spam.guard.caspershouse.com
>
> "Ron Vecchi" <rvecchi@xilehdvecchi.com> wrote in message
> news:u3CTh06yDHA.4060@TK2MSFTNGP11.phx.gbl...[color=green]
> > I need to allow my control when it is visible to capture the mouse and[/color][/color]
not[color=blue][color=green]
> > let any other control react to mouse events until control is hidden.
> >
> > Similar to ContextMenu
> >
> > Any Suggestions
> >
> > --
> > Ron Vecchi
> >
> >
> >[/color]
>
>[/color]


Jeffrey Tan[MSFT]
Guest
 
Posts: n/a
#4: Nov 15 '05

re: Capture mouse when control is visible



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.

Jeffrey Tan[MSFT]
Guest
 
Posts: n/a
#5: Nov 15 '05

re: Capture mouse when control is visible



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.

Ron Vecchi
Guest
 
Posts: n/a
#6: Nov 15 '05

re: Capture mouse when control is visible


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


""Jeffrey Tan[MSFT]"" <v-jetan@online.microsoft.com> wrote in message
news:bdn5hwN0DHA.3532@cpmsftngxa07.phx.gbl...[color=blue]
>
> 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[/color]
technical,[color=blue]
> 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.
>[/color]


Jeffrey Tan[MSFT]
Guest
 
Posts: n/a
#7: Nov 15 '05

re: Capture mouse when control is visible



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.

Closed Thread