如何将“System.Windows.Input.Key"转换为“System.Windows.Forms.Keys"? [英] How can I convert 'System.Windows.Input.Key' to 'System.Windows.Forms.Keys'?

查看:30
本文介绍了如何将“System.Windows.Input.Key"转换为“System.Windows.Forms.Keys"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 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.

这篇关于如何将“System.Windows.Input.Key"转换为“System.Windows.Forms.Keys"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆