C# - Detect Mouse Click Outside Form

A

akowald

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
 
A

akowald

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(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef
hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(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.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

If anybody could help I really need it. :)
 
A

akowald

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top