2016-04-03 20 views
0

Basit bir dizeyi bir anahtara dönüştürmeye çalışıyorum, bir çift çözüm buldum ama çoğunun winform'ları var ya da tam kodu göstermediler. anla.Bir dize bir anahtar dönüştürün

Bu i

namespace KeyDown 
{ 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     public string CustomKey = "B"; 
     public MainWindow() 
     { 
      InitializeComponent(); 
      activeArea.Focus(); 
     } 

     private void activeArea_KeyDown(object sender, KeyEventArgs e) 
     { 
      if (e.Key == Key.CustomKey) 
      { 
       MessageBox.Show("Key Pressed"); 
      } 
     } 
    } 
} 

cevap

0

Sen WPF System.Windows.Input.Key enum kullanabilirsiniz ulaşmak istediğimiz öldürmekle geçerli:

using System.Windows.Input; 

... 

public Key CustomKey = Key.B; 

// or this if you really want to convert the string representation 
public Key CustomKey = (Key)Enum.Parse(typeof(Key), "B"); 


private void activeArea_KeyDown(object sender, KeyEventArgs e) 
{ 
    if (e.Key == CustomKey) 
    { 
     MessageBox.Show("Key Pressed"); 
    } 
} 
+0

bu mükemmel çalışıyor teşekkür ederiz! – Simon

+0

@Simon, rica ederim :) –

İlgili konular