相关疑难解决方法(0)

如何将字符转换为等效的System.Windows.Input.Key枚举值?

我想写一个这样的函数,

        public System.Windows.Input.Key ResolveKey(char charToResolve)
        {
            // Code goes here, that resolves the charToResolve
            // in to the Key enumerated value
            // (For example with '.' as the character for Key.OemPeriod)

        }
Run Code Online (Sandbox Code Playgroud)

我知道我可以写一个巨大的Switch-case来匹配角色,但还有其他方法吗?这个问题是Key枚举的字符串可能与字符不匹配,因此Enum.IsDefined不起作用

有任何想法吗?

更新:这是在Windows环境中

.net c# enums key input

16
推荐指数
2
解决办法
3万
查看次数

键(枚举)到字符串

如何将Key(KeyEventArgs中的Key)转换为字符串.

例如,如果用户输入" - ":

e.Key.ToString() = "Subtract"
new KeyConverter().ConvertToString(e.Key) = "Subtract"
Run Code Online (Sandbox Code Playgroud)

我想要的是得到" - "的结果,而不是"Substract"......

c# enums key

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×2

enums ×2

key ×2

.net ×1

input ×1