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

We have done with the project. But now we want to track every event in the text document that user have performed for debugging purpose, when an action/event is performed in application. for tracking I have to call method in every event that is in all the forms in the application, but it is a lengthy procedure. I want to do it by writing a method, so that when ever an action is performed in the application that method should call.

Can any one help me in this.
Posted
Updated 27-Jan-16 0:43am
v3
Comments
Kornfeld Eliyahu Peter 27-Jan-16 5:26am    
Andy Lanng 27-Jan-16 5:48am    
Read the link above. It's a little long but it explains why we can't help without more information.
A good rule-of-thumb is to read the question and try to think of what kind of answer you would expect the question to get.
And be specific. Questions like "How to program?" will be flagged and removed

1 solution

I think that is simple to do but I can only do that in c#, if you don't mind
1) you have to subscribe to which ever event of the form you want to handle when it's fired. A form has many events that can be handled. for example, if you want a method "EventMethod_Click" to be called any time a form is clicked, write the following in the form's constructor:
form1.Click += new EventHandler(EventMethod_Click);

with the above code, you've just subscribed to the Form's Click event. therefore, any time the form is clicked, the method "EventMethod_Click" will be called.

2) create a private void method named "EventMethod_Click" with two parameters, object and eventArgs

private void EventMethod_Click(object sender, EventArgs e)
{
// Do what ever you want here
}

I hope that helps you, sorry for answering with c#.
 
Share this answer
 
Comments
vinod kumar chanda 27-Jan-16 7:13am    
Here in our application I want to track every click event irrespective of the control not the single event. I want to do it in a shortest way. Is there any method which fires when an action is performed by the user.
Makinde A. 27-Jan-16 8:55am    
I don't know if what am about to say is limited to c#, but I think all windows form have a property Form.Controls that returns collection of all Controls on the form. You can iterate through all the controls on the form and subscribe to their Click event and passing thesame method.

for (int i = 0; i <form1.Controls. length; i++)
{
form1.Controls[i].Click += new EventHandler(EventMethod_Click);
}

or you can call some API functions to set lowlevelMouseHook instead.

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