C#程序中的Button按钮实现键盘上的退格键和Delete的功能

2024-11-18 04:23:56
推荐回答(2个)
回答1:

private void Button_Click_1(object sender, RoutedEventArgs e)
{
int index = tbx.SelectionStart;
if (tbx.SelectionLength > 0)
{
tbx.Text = tbx.Text.Remove(tbx.SelectionStart, tbx.SelectionLength);
tbx.SelectionStart =index;
}
else if (tbx.SelectionStart < tbx.Text.Length)
{
tbx.Text = tbx.Text.Remove(tbx.SelectionStart, 1);
tbx.SelectionStart = index;
}
tbx.Focus();
}

回答2:

那你直接往文本框送这两个按键不就行了