在WPF C#项目中,没有KeyChar属性可以从textBox获取字符。是否有任何替代方法可以按任意键获取字符?
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.keyChar == (char)13)
{
webBrowser.Navigate(textBox1.Text);
}
}
答案 0 :(得分:1)
试试这个:
if (e.Key == Key.Return)
答案 1 :(得分:1)
试试这个肯定会在WPF中运行
<TextBox x:Name="txtbx" KeyDown="OnKeyDown" Height="23" Width="250">
</TextBox>
private void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Home(or whatever key you want, if it is numeri try with D0, D1,D2 etc.))
{
txtbx.Text = "You Entered: " + txtbx.Text;
}
}