方法已经知道了,参考了以下的做法:http://blog.csdn.net/linjf520/article/details/8187637
但有个问题是如何在keydown事件中按了上下键后不停的回溯历史记录呢?还有就是如何让光标停留在最后一行的末尾处,我按了上下键光标老是跑上去了,请各位帮忙了,谢谢!

解决方案 »

  1.   

    addSendRec函数里最后一句代码应该是下面这样吧
    sendRecordListIdx = sendRecordList.Count-1;
    光标停在最后一行末尾
     this.textBox_send_chat_txt.SelectionStart = this.textBox_send_chat_txt.Text.Length-1;
     this.textBox_send_chat_txt.SelectionLength = 1;
      

  2.   

    在keyDown事件里最后写上下面这句代码,光标就不往上跑了
    e.Handled = true;
      

  3.   

         if (e.KeyCode == Keys.Up)
                {
                    this.textBox_send_chat_txt.Text = upGetSendRec();
                }
                else if (e.KeyCode == Keys.Down)
                {
                    this.textBox_send_chat_txt.Text = downGetSendRec();
                }
    e.Handled = true;  //你测一下,如果不行,就把这句放在此函数第一行试试
      

  4.   

    你不是已经实现了吗?
    upGetSendRec()和downGetSendRec()函数里不是获取最后一行的记录吗
      

  5.   

    if (e.KeyCode == Keys.Up)
    {
        this.textBox_send_chat_txt.Text = upGetSendRec();
    }
    else if (e.KeyCode == Keys.Down)
    {
       this.textBox_send_chat_txt.Text = downGetSendRec();
    }
    textBox_send_chat_txt是多行文本,他这里这么写的话就直接替换为历史记录行了,要textBox_send_chat_txt.AppendText(upGetSendRec())或textBox_send_chat_txt.AppendText(downGetSendRec()),但这样的话就按上下键就无限的往后添加历史记录行,做法是要先删除最后一行的内容然后在AppendText