具体如下,请问在C#程序中的Button按钮实现键盘上的退格键和Delete的功能?

1、就是当点击一个按钮时,文本框的内容从后向前减少,每按一次文本框内容减少一个,就是同键盘上的退格键功能一样
2、当点击另一个按钮时,实现从鼠标光标后面减一,就是同键盘上Delete功能一样

当年话下
浏览 254回答 2
2回答

www说

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

米琪卡哇伊

private&nbsp;void&nbsp;button2_Click(object&nbsp;sender, EventArgs e){&nbsp;&nbsp;&nbsp;&nbsp;textBox1.Focus();&nbsp;&nbsp;&nbsp;&nbsp;SendKeys.Send("{BACKSPACE}");}private&nbsp;void&nbsp;button3_Click(object&nbsp;sender, EventArgs e){&nbsp;&nbsp;&nbsp;&nbsp;textBox1.Focus();&nbsp;&nbsp;&nbsp;&nbsp;SendKeys.Send("{DEL}");}
打开App,查看更多内容
随时随地看视频慕课网APP