【发布时间】:2011-04-17 00:40:21
【问题描述】:
我正在开发这个应用程序,它需要在应用程序聚焦时读取每个按键。
我可以读取除 3 个键之外的所有键:空格键、Enter 和退格键。
这是我项目中的代码 sn-p:
XAML 文件:
<TextBox Height="108" HorizontalAlignment="Left" Margin="12,12,0,0" Name="textBox1" VerticalAlignment="Top" Width="354" AcceptsReturn="True" AcceptsTab="True" KeyDown="textBox1_KeyDown" IsReadOnly="False" IsEnabled="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" />
CS 文件:
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return || e.Key == Key.Space)
MessageBox.Show("" + e.Key);
}
【问题讨论】: