Autor Beitrag
Ccenter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 154

Win7
C#
BeitragVerfasst: Di 06.07.10 20:09 
Hallo,
ich deklariere wie folgt eine Variable:

string str1 = textBox1.Text;

nun möchte ich den erhaltenen Buchstaben als Teil eines Hotkeys verwenden.
ausblenden C#-Quelltext
1:
2:
3:
4:
Hotkey iExplorer = new Hotkey();
iExplorer.Enabled = true;
iExplorer.HotkeyPressed += new EventHandler(iExplorer_HotkeyPressed);
iExplorer.KeyCode = Keys.

....und an dieser stelle liegt mein Problem. Vorgegeben werden nach "Keys." nur Buchstaben, jedoch nicht meine deklarierte Variable.
Wie bekomme ich das gelöst?
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Di 06.07.10 20:47 
Solange es wirklich nur um Buchstaben geht, sollte das mit Enum.Parse am schnellsten zu lösen sein.

_________________
>λ=
Ccenter Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 154

Win7
C#
BeitragVerfasst: Di 06.07.10 22:53 
Tut mir leid aber mir ist nicht ganz klar wie ich das nun anwenden soll.
Könntest du bitte ein Beispiel nennen ?
danielf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1012
Erhaltene Danke: 24

Windows XP
C#, Visual Studio
BeitragVerfasst: Mi 07.07.10 08:10 
Mit der statischen Parse-Methode der Enum Klasse kann man einen String (oder ein Zeichen) in ein entsprechendes Enum verwandeln. Siehe dazu auch MSDN. Dort findest du übrigens zu fast allen Klassen und Methoden Hilfe und Beispiele.

ausblenden C#-Quelltext
1:
iExplorer.KeyCode = (Keys) Enum.Parse(textBox1.Text);					


Gruß
Ccenter Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 154

Win7
C#
BeitragVerfasst: Mi 07.07.10 23:51 
Ok, vielen Dank.