我需要將System.Windows.Forms.Keys設置爲我已分配的字符串。如何將字符串值分配給System.Windows.Forms.Keys?
我正在使用第三方.Net控件,它允許我將熱鍵分配給控件,並使用System.Windows.Forms.Keys來設置熱鍵。例如:
this.systemHotKey1.SetHotKey(System.Windows.Forms.Keys.S); //Assign S as the HotKey
然而,System.Windows.Forms.Keys不會讓我一個字符串分配給它,我需要的實際值分配給它。例如,這工作得很好:
System.Windows.Forms.Keys.S (for the hotkey S on the keyboard).
但我想要做這樣的事情:
{
string tmpString = "S";
this.systemHotKey1.SetHotKey(System.Windows.Forms.Keys.tmpString); //This does not work
}
可有人請告訴我一個辦法,我可以指定一個字符串系統。 Windows.Forms.Keys,所以我可以做到這一點?
我得到一個錯誤,當我這樣做:參數類型「對象」是不能分配給參數類型「System.Windows.Forms.Keys」對代碼行寫着 「kc.ConvertFromString(tmpstring)」 – fraXis
你試過將其轉換爲按鍵式this.systemHotKey1.SetHotKey((System.Windows.Forms.Keys)kc.ConvertFromString(tmpstring))?; – davidcoder