首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

初学者求指导 richtextbox自动填值

2013-02-25 
菜鸟求指导richtextbox自动填值本帖最后由 gzm998128gzm 于 2013-02-18 17:24:36 编辑原先richtextbox里面

菜鸟求指导 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;
            }
        }

热点排行