我怎么可以转换“System.Windows.Input.Key”到“System.Windows.Forms.Keys”? [英] How can I convert 'System.Windows.Input.Key' to 'System.Windows.Forms.Keys'?
本文介绍了我怎么可以转换“System.Windows.Input.Key”到“System.Windows.Forms.Keys”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发展在WPF应用程序,但某些组件使用的WinForms编写的。我wan't这些组件拉关键的姿态从WPF的一部分,将它们转换为键枚举(在WinForms的使用)。
有没有为内置的转换? (可能不会) 你知道比大开关案更容易的方法来做到这一点?
解决方案
键formsKey = ...;
键wpfKey = ...;
wpfKey = KeyInterop.KeyFromVirtualKey((INT)formsKey);
formsKey =(密钥)KeyInterop.VirtualKeyFromKey(wpfKey);
借助 KeyInterop类是钥匙,再加上事实上,Windows窗体键
枚举有相同的整数值的赢32个虚拟按键codeS。
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);
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.
这篇关于我怎么可以转换“System.Windows.Input.Key”到“System.Windows.Forms.Keys”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文