如何将“System.Windows.Input.Key"转换为“System.Windows.Forms.Keys"?

如何将“System.Windows.Input.Key

问题描述:

我正在用 WPF 开发应用程序,但有些组件是使用 WinForms 编写的.我不想这些组件从 WPF 部分提取关键手势并将它们转换为 Keys 枚举(在 WinForms 中使用).

I'm developing application in WPF but some components are written using WinForms. I wan't these components to pull key gesture from WPF part and convert them to Keys enum (used in WinForms).

是否有内置转换器?(可能不是)你知道比大开关盒更容易"的方法吗?

Is there a built in converter for that? (probably not) Do you know "easier than big switch case" method to do that?

Keys formsKey = ...;
Key wpfKey = ...;
wpfKey = KeyInterop.KeyFromVirtualKey((int)formsKey);
formsKey = (Keys)KeyInterop.VirtualKeyFromKey(wpfKey);

KeyInterop 类 是键"以及 Windows 窗体 Keys 枚举具有与 Win 32 虚拟键代码相同的整数值这一事实.

The KeyInterop class is the "key," plus the fact that the Windows Forms Keys enumeration has the same integer values as the Win 32 virtual key codes.