Scroll to the end of RichTextbox

来源:互联网 发布:unity3d集成百度地图 编辑:程序博客网 时间:2024/05/17 23:11
用 RichTextBox 做聊天内容显示的哥们,估计都遇到过这个问题。
使用SendMessage API向RichTextBox控件发送消息是最简单的一种解决方法。
using System.Runtime.InteropServices;

[DllImport("User32.dll",EntryPoint="SendMessage")]
private static extern int SendMessage(
  IntPtr hWnd, // handle to destination window
  uint Msg, // message
  uint wParam, // first message parameter
  uint lParam // second message parameter
  );

private const int WM_VSCROLL = 0x0115;
private const int SB_BOTTOM = 7;

private void btnSend_Click(object sender, System.EventArgs e)
{
  this.richTextBox1.AppendText("1");
  SendMessage(this.richTextBox1.Handle, WM_VSCROLL, SB_BOTTOM, 0);
}
 
原创粉丝点击