【发布时间】:2014-03-17 14:09:58
【问题描述】:
我的程序有大问题!
http://www.directupload.net/file/d/3564/9lsazq3e_png.htm
如果我点击richTextBox,我想用按钮上的数字填充它。
我现在怎么做--->(每个按钮都有这个点击事件)
private void digits_Click_2(object sender, EventArgs e)
{
if (sender is Control)
{
rtxtLast.Text += (sender as Control).Text;
rtxtLast.SelectionStart = rtxtLast.Text.Length;
rtxtLast.Focus();
}
}
我可以用数字填充richTextBox,但只能在文本的末尾。
但我想在光标处插入文本
对于光标,我有左/右箭头(或通过触摸显示屏)
顺便说一句,我有一个完整的触摸系统,所以我必须使用按钮(我没有键盘/鼠标)
空格键也有同样的问题(“Leertaste”)
private void button36_Click(object sender, EventArgs e)
{
rtxtLast.Text += " ";
rtxtLast.SelectionStart = rtxtLast.Text.Length;
rtxtLast.Focus();
}
这就是我删除的方式(“Löschen”)
private void button11_Click(object sender, EventArgs e)
{
if (rtxtLast.SelectionStart > 0)
{
int index = rtxtLast.SelectionStart;
rtxtLast.Text = rtxtLast.Text.Remove(rtxtLast.SelectionStart - 1, 1);
rtxtLast.Select(index - 1, 1);
rtxtLast.Focus();
}
else if (rtxtLast.Text != string.Empty)
{
rtxtLast.Text = rtxtLast.Text.Remove(rtxtLast.Text.Length - 1);
}
}
左右两边都是这个
private void left2_Click(object sender, EventArgs e)
{
if (rtxtLast.SelectionStart > 0)
{
int index = rtxtLast.SelectionStart;
rtxtLast.Select(index - 1, 1);
rtxtLast.Focus();
}
}
private void right2_Click(object sender, EventArgs e)
{
if (rtxtLast.SelectionStart > -1)
{
int index = rtxtLast.SelectionStart;
rtxtLast.Select(index + 1, 1);
rtxtLast.Focus();
}
}
左/右和删除正在工作 但我还没有找到数字的解决方案..
我知道代码是错误的,但我不知道如何正确地做到这一点
有人可以帮我吗?
问候 阿图尔
【问题讨论】:
标签: winforms button cursor richtextbox