Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to call to click method from another method
can is ir possible?

i want to call all method in class one click method event occurs and stay alwayes there
Posted
Comments
agent_kruger 23-Dec-13 1:52am    
please explain what do you want to achieve above statement is not clear.

You can - it's just a method after all - but it's not considered a good idea.
It's a much, much better idea to create a new method which does the work and call that from your event handler and the other location(s) instead.
 
Share this answer
 
Assuming this is Windows Forms:

Controls inheriting from Control/ButtonBase, like a Button, provide a method for triggering a Click Event in code: 'PerformClick();

For other Controls, depending on the Control, and what you want to do, different techniques can be used.

In one use-case you may want to simulate an actual physical mouse-click on a Control, which would, normally, give Focus to the Control; in another use-case, perhaps your goal is simply execute to the code in the Click EventHandler. Or, perhaps, you want both behaviors ?

You can usually "get away with" invoking a Click EventHandler's code by simply calling it with "dummy" parameter arguments:
C#
private void SomeMethod( ... some parameters , , ,)
{
     SomeControl_Click(null, null);
}
Begin Edit:
As OriginalGriff notes in his response, if you are going to make use of the code in an EventHandler from outside the EventHandler, it is much better to take that code and put it in a method of its own which both the EventHandler and your "external" code can call.

If you really wish to simulate a physical mouse-click anywhere on the screen, you must use the Win API: good source code here: [^]. If you are a beginner in C# and .NET, I'd suggest you wait until you are more advanced before using API based code.
End Edit

If you give a specific example of what you are trying to do, and what Controls are involved, you can get a more specific answer.
 
Share this answer
 
v2

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