Reputation: 414
I want to catch the click event of the button which is clicked on Windows Form Application lets say in Application A and I want to catch it in Application B which is also a Windows Form Application.
I have created both the Applications and added the button in Application A. Now when the button is clicked in Application A, I want to catch the event in Application B.
Please guide.
Upvotes: 0
Views: 1087
Reputation: 1555
You can use SetWinEventHook or a WH_MOUSE_LL hook (P/Invoke)
(tested on Windows 10, with VS 2015)
(also IUIAutomationEventHandler but more complicated)
Upvotes: 0
Reputation: 63
I can explain you, how you may catch the Button Click event a little bit otherwise.
You can create the instance of your 2nd Form in your first one or in a reachable Class, then calling a Public Method in your 2nd Form or in your class, which does what you want.
Example Form 1:
var _secondForm = new Form2();
private void Form1_Load(object sender, EventArgs e)
{
_secondForm.Open();
}
private void button1_Click(object sender, EventArgs e)
{
MethodInSecondForm()
}
and your Second Form:
public void MethodInSecondForm()
{
// Event here
}
You can create this instance in a Class, too and make it easier.
Upvotes: 0
Reputation: 63
There isn't a "quick" way to share .NET events between different processes. You need to catch the event in the same application which raised it, implement an inter-process communication mechanism (WCF, socket, ...) between Application A and application B and use it to send the event data from A to B.
See this question and related answers for more details: Listen for events in another application
Upvotes: 2