读书人

初学者求指导 richtextbox自动填值

发布时间: 2013-02-25 10:23:36 作者: rapoo

菜鸟求指导 richtextbox自动填值
本帖最后由 gzm998128gzm 于 2013-02-18 17:24:36 编辑 原先richtextbox里面有值了,现在我在某一行大哥回车键 ,在新出来的那行自动填值(什么值无所谓)
[解决办法]
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{

if (e.KeyCode == Keys.Enter)
{
richTextBox1.Text += "qwer";
richTextBox1.Select(richTextBox1.TextLength, 0);

}
}
[解决办法]
用AppendText
[解决办法]
\r\n是换行


private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
{
richTextBox1.AppendText("\r\naaa");
e.Handled = true;
}
}


[解决办法]
private void richTextBox1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
{
int index = richTextBox1.GetFirstCharIndexOfCurrentLine();
int line = richTextBox1.GetLineFromCharIndex(index);
String[] lines = richTextBox1.Lines;
lines[line] = "24324234234234";
richTextBox1.Lines = lines;
}
}
[解决办法]
光标你可以Set的啊
        private void richTextBoxCh_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)


{
int pos = richTextBoxCh.SelectionStart;
string str = richTextBoxCh.Text;

string str2 = str.Substring(0, pos) + "test" + str.Substring(pos);

richTextBoxCh.Text = str2;
richTextBoxCh.SelectionStart = pos ;

e.Handled = true;
}
}

读书人网 >C#

热点推荐