键枚举有哪些格式可用?

发布于 2024-09-15 10:12:08 字数 417 浏览 2 评论 0原文

我有下一个问题。我需要以文本形式表示按下的按键组合。我从 KeyEventArgs e 得到了按键... 当我尝试使用以下代码时 e.KeyData.ToString(); 我得到了这样的东西:N, Control ....但我想得到Ctrl+N字符串。
我认为这必须是 String.Format 的特定格式,因为当我将 Keys 类型的属性绑定到我在表格单元格中看到的 DataGridView 时字符串Ctrl+N。这意味着 DataGridView 可以做到这一点,而且我认为这不是手动完成的......

非常感谢!

I have a next problem. I need to represent a pressed keys combination in a text form. I got pressed keys from KeyEventArgs e...
And when I try to use following code
e.KeyData.ToString(); I got something like this: N, Control .... But I want to get Ctrl+N string.
I think that must be present specific format for String.Format because when i bind property with type Keys to the DataGridView I saw in the table cell string Ctrl+N. It's mean that DataGridView can do this, and i think this is not done manually...

Thanks a lot!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪冰清 2024-09-22 10:12:08

Keys 值可能使用其所属的 TypeConverter 显示。

如果您想模拟 DataGridView 的行为,您应该使用

TypeConverter converter = TypeDescriptor.GetConverter(typeof(Keys));
string displayName = converter.ConvertToString(e.KeyData);

Keys 类型标记为 [TypeConverter(typeof(KeysConverter))] ,这是 GetConverter 应该返回的内容。

The Keys values are probably displayed using the TypeConverter belonging it.

If you want to emulate the behavior of the DataGridView, you should use

TypeConverter converter = TypeDescriptor.GetConverter(typeof(Keys));
string displayName = converter.ConvertToString(e.KeyData);

The Keys type is tagged with [TypeConverter(typeof(KeysConverter))], which is what GetConverter should return.

冷默言语 2024-09-22 10:12:08

根据MSDN,没有内置的东西可以做到这一点。我怀疑网格只是用“,”代替“+”。

According to MSDN, there is nothing built-in to do this. I suspect the grid is just substituing ", " for "+".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文