简体   繁体   中英

Handling a WinForms button's Click event from a separate WPF application

Summary: So I have two applications: one is WinForms and the other is WPF. I am trying to figure out how to click a button in the WinForms app and have the WPF app respond to that click.

So to get more detailed, I am working on an existing WinForms application, adding new features. For one of those features, I needed to create a separate WPF application with an InkCanvas that sits on top of the WinForms application and allows the user to draw over the WinForms app.

I have 3 buttons on the WinForms app that are meant to control the InkCanvas: one to enable drawing, one to enable erasing, and one to clear the canvas. What I need to figure out is how to handle those 3 buttons' Click events in the WPF application.

I've been looking at things like PRISM's EventAggregator (although I don't know if that would work between separate processes) and WCF. WCF seems like what I should be using, but I have no experience using it, so it is slow going. I have come across articles about WCF Duplex Services ( link )( link )

So I guess my question is: what is the best approach to handling a WinForms button's Click event in a separate WPF application? Apologies in advance if this question has already been asked or if it is too vague.

WinForms can host WPF elements using the ElementHost control, built into the Winforms control library. If that doesn't work in this case (because you are using transparency), you can try using a new WPF window that you overlay on top of the application (see Open WPF window in WindowsForm APP ).

This way you can wire up event handlers and communication without having to worry about IPC methods or managing application lifetimes between two different executables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM