Click here to Skip to main content
15,891,993 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

My question is simple, I have created a program, but when there has been 10 minutes of inactivity, the application will Close, like this:
C#
Application.Close();


I already search about Mouse Move event and there come some errors, in my Form1.Designer.cs is an error in this line:
C#
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);

The error says:
Cannot assign to 'MouseMove' because it is a 'method group'

Regards,
KZ
Posted
Updated 7-Dec-12 9:32am
v2
Comments
Sergey Alexandrovich Kryukov 7-Dec-12 15:31pm    
You need to show a bit more of your code, not just one line: what is "this", what is the context of this line, what is Form1_MouseMove...
--SA

This is how to do it:
C#
this.MouseMove += (sender, eventArgs) => { // actual parameter types are inferred by a compiler from the known event type
    // from here, call whatever you want, using eventArgs parameters
};

You can do the same using anonymous method even if you work with C# v.2 where lambda expression were not yet introduced:
C#
this.MouseMove += deletage(object sender, MouseEventArgs eventArgs) { 
    // ...
};


[EDIT]

By the way, never ever use auto-generated names like "Form1_MouseMove" — they violate (good) Microsoft naming conventions; don't use underscore, numerics, etc. Always rename all such names to something semantic. What do you think refactoring engine for?

—SA
 
Share this answer
 
v2
Comments
__TR__ 8-Dec-12 2:59am    
My 5!
Sergey Alexandrovich Kryukov 8-Dec-12 6:20am    
Thank you,
--SA
Please clarify: you want to close you app after the timeout, or it is closing as a bug, and you want to avoid this? In the first case, you could consult this article: Application Idle[^], in the later case, you should post a little more of your code.
 
Share this answer
 
Comments
Zoltán Zörgő 8-Dec-12 13:45pm    
Would be interesting to know, why the "2"... :(
Jibesh 10-Dec-12 16:33pm    
Application Idle is the best choice that is more suited your need.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900