QQ聊天窗口效果
rtbDetail:显示聊天信息
rtbChat:用户输入信息
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsFormsApplication4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport("user32.dll")] private static extern int SendMessage(IntPtr hWnd,int msg,int wParam,IntPtr IParam); private const int WM_VSCROLL = 0x115; private const int SB_BOTTOM = 7; private int lastSelectedIndex = -1; private void btnSend_Click(object sender, EventArgs e) { rtbDetail.Text += rtbChat.Text+Environment.NewLine; rtbChat.Text = ""; SendMessage(rtbDetail.Handle,WM_VSCROLL,SB_BOTTOM,new IntPtr(0)); rtbChat.Focus(); } private void Form1_Load(object sender, EventArgs e) { rtbChat.Focus(); this.AcceptButton = btnSend; } } }