我尝试使用箭头键增加文本框中的值。我正在使用wfp,c#
if (ke.Key == Key.Up || ke.Key == Key.Down)
ke.Handled = false;// need a method in here
如何使用箭头键增加文本框中的值?
答案 0 :(得分:2)
WPF中的texbox
<TextBox Name="textbox1" HorizontalAlignment="Left" Text="0" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Margin="154,138,0,0" PreviewKeyDown="TextBox_KeyDown"/>
代码隐藏
private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
int currentNumber = Convert.ToInt32(textbox1.Text);
if (e.Key == Key.Up)
{
textbox1.Text = (currentNumber + 1).ToString();
}
else if (e.Key == Key.Down)
{
textbox1.Text = (currentNumber - 1).ToString();
}
}