C# – Pass key press from win forms to wpf

c++interopwinformswpf

I have a windows forms Form that has a menu bar that grabs Ctrl-C. Inside the form's copy handler is a switch statement calls the correct copy method depending on what kind of control is selected.

I have now added a WPF UserControl as one of the child controls. In the UserControl, is a TextBox. I would like to have Ctrl-C activate the TextBox's Copy command. What is the easiest way to launch that command? Or maybe there is an easy way to fire a keypress event on the usercontrol?

Best Solution

I am not very much sure about how to send the KeyPress event on usercontrol, but for the textbox copy you can fire ApplicationCommands.Copy command and WPF textbox automatically handle the copy command for it, if focus at TextBox.

ApplicationCommands.Copy.Execute(null, null); inside your copy handler if user control is selected.