Connecting Tech Pros Worldwide Forums | Help | Site Map

C# - Detect Mouse Click Outside Form

akowald@gmail.com
Guest
 
Posts: n/a
#1: Jun 3 '06
There's another topic like this but the code posted is in VB.NET.

Well I need some help detecting mouse clicks outside the form. An event
handler would be great but I can work with anything.

Thanks in advance,

Alex


Vadym Stetsyak
Guest
 
Posts: n/a
#2: Jun 3 '06

re: C# - Detect Mouse Click Outside Form


You can utilize windows hooks in order to detect all mouse clicks...

http://www.codeproject.com/csharp/globalhook.asp
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

<akowald@gmail.com> wrote in message
news:1149297954.126092.261850@g10g2000cwb.googlegr oups.com...[color=blue]
> There's another topic like this but the code posted is in VB.NET.
>
> Well I need some help detecting mouse clicks outside the form. An event
> handler would be great but I can work with anything.
>
> Thanks in advance,
>
> Alex
>[/color]


akowald@gmail.com
Guest
 
Posts: n/a
#3: Jun 4 '06

re: C# - Detect Mouse Click Outside Form


His code was written in VS 2003 and I'm using VS 2005. I implemented
his code into my project and it threw an exception...

System.Exception was unhandled
Message="SetWindowsHookEx failed."
Source="rsmm"
StackTrace:
at GlobalHookDemo.UserActivityHook.Start() in C:\Documents and
Settings\Administrator\My Documents\Visual Studio
2005\Projects\rsmm\rsmm\UserActivityHook.cs:line 123
at GlobalHookDemo.UserActivityHook..ctor() in C:\Documents and
Settings\Administrator\My Documents\Visual Studio
2005\Projects\rsmm\rsmm\UserActivityHook.cs:line 29
at rsmm.Form1.Form1_Load(Object sender, EventArgs e) in
C:\Documents and Settings\Administrator\My Documents\Visual Studio
2005\Projects\rsmm\rsmm\Form1.cs:line 21
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean
fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow( HandleRef
hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolea n value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at rsmm.Program.Main() in C:\Documents and
Settings\Administrator\My Documents\Visual Studio
2005\Projects\rsmm\rsmm\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

If anybody could help I really need it. :)

akowald@gmail.com
Guest
 
Posts: n/a
#4: Jun 4 '06

re: C# - Detect Mouse Click Outside Form


For the sake of other people that have the same as me I'll post this:

This is how to get the above code working under VS 2005:

(this is from the comments of the codeproject post)

You just need to UNCHECK the check box in the project properties that
says:
"Enable visual studio hosting process"

In the menu:

Project -> Project properties... -> Debug -> Enable the visual studio
hosting process

Closed Thread