Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

Receiving mouse events (WM_MOUSEMOVE, etc) outside of form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason - 20 Sep 2004 22:55 GMT
I'm trying to implement some pretty basic behavior in c#/.net 1.1
Forms but can't seem to find all the requisite pieces. When a user
clicks on the background of the form, I want the app to start
receiving MouseMove updates -- whether the pointer is over the form or
not (this being the crucial part) -- until the next MouseDown. It's
easy to receive MouseMove events while the pointer is over the form
but not when the pointer leaves. (Forms continue to receive
out-of-window MouseMove updates if a mouse-button is held down, ie a
drag, but not when just moving around.)

So, is there some simple way to do this in .NET?

The one approach that I've encounted which seems to have promise is
using the User32 SetCapture function. I can successfully capture the
mouse, but then I'm not sure how to receive the event messages
(specifically WM_MOUSEMOVE).

Okiedokie. Any ideas?? TIA
Sijin Joseph - 21 Sep 2004 05:19 GMT
You can use Control.Capture property to get mouse events that happen
outside your form.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> I'm trying to implement some pretty basic behavior in c#/.net 1.1
> Forms but can't seem to find all the requisite pieces. When a user
[quoted text clipped - 14 lines]
>
> Okiedokie. Any ideas?? TIA
Jason - 21 Sep 2004 15:15 GMT
Well, actually, that only works when _dragging_ outside of the Form
(or control). So, for example, if the user presses a mouse button,
then drags outside the Form/Control while still holding the button,
said Form/Control receives MouseMove updates. However, even if the
Control.Capture is set to true, it won't receive general MouseMove
updates from outside the From... any ideas about how to do this?

Thanks!
Jason

> You can use Control.Capture property to get mouse events that happen
> outside your form.
>
> Sijin Joseph
> http://www.indiangeek.net
> http://weblogs.asp.net/sjoseph
Stoitcho Goutsev \(100\) [C# MVP] - 21 Sep 2004 15:26 GMT
Hi Jason,

Mouse capture won't help you with this. Mouse capture in windows works only
while mouse button is held down. Even windows form is designed in a way
where capture is released as soon as a mouse button is released. Otherwise
receiving mouse events from this point on is unreliable.

The only way to track the mouse if not button is pressed, IMHO, is to
install  a windows hook. Fortunately WH_MOUSE_LL hooks can be programmed
with .NET.

The following is an article from MSDN Magazine obout writing windows hooks
in .NET

http://msdn.microsoft.com/msdnmag/issues/02/10/CuttingEdge/

The autor (Dino Esposito) doesn't talk about mouse hooks but there are good
helper class for writing windows hooks.

Signature

HTH
Stoitcho Goutsev (100) [C# MVP]

> I'm trying to implement some pretty basic behavior in c#/.net 1.1
> Forms but can't seem to find all the requisite pieces. When a user
[quoted text clipped - 14 lines]
>
> Okiedokie. Any ideas?? TIA

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.