我如何分配一个字符串值,为System.Windows.Forms.Keys? [英] How do I assign a string value to System.Windows.Forms.Keys?

查看:245
本文介绍了我如何分配一个字符串值,为System.Windows.Forms.Keys?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 System.Windows.Forms.Keys 以,我分配一个字符串。

I need to set System.Windows.Forms.Keys to a string that I have assigned.

我使用的是第三方.NET控件,让我热键分配给控件,它使用的 System.Windows.Forms.Keys 可设置热键。例如:搜索结果
this.systemHotKey1.SetHotKey(System.Windows.Forms.Keys.S); //分配S作为热键

I am using a 3rd party .Net control that lets me assign the HotKey to the control, and it uses System.Windows.Forms.Keys to set the HotKey. For example:

this.systemHotKey1.SetHotKey(System.Windows.Forms.Keys.S); //Assign S as the HotKey

不过,System.Windows.Forms.Keys不会让我一个字符串分配给它,我需要以实际值分配给它。例如,这工作得很好:

However, System.Windows.Forms.Keys will not let me assign a string to it, I need to assign an actual value to it. For example this works fine:

System.Windows.Forms.Keys.S (for the hotkey S on the keyboard).



搜索结果
,但我想要做的是这样的:



But I want to do something like this:

{
string tmpString = "S";
this.systemHotKey1.SetHotKey(System.Windows.Forms.Keys.tmpString);  //This does not work
}



搜索结果
是否有人可以告诉我一个办法,我可以一个字符串赋值为System.Windows.Forms.Keys这样我就可以做到这一点?



Can someone please show me a way I can assign a string to System.Windows.Forms.Keys so I can accomplish this?

推荐答案

您可以通过使用KeysConverter

You can do this by using KeysConverter

string tmpString = "S";
KeysConverter kc = new KeysConverter();
this.systemHotKey1.SetHotKey(kc.ConvertFromString(tmpstring));

这篇关于我如何分配一个字符串值,为System.Windows.Forms.Keys?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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