滚动可以通过TopIndex来设置:
private void AddMsg(string msg)
{
bool scroll = false;
if (this.listBox1.TopIndex == this.listBox1.Items.Count - (int)(this.listBox1.Height / this.listBox1.ItemHeight))
scroll = true;
this.listBox1.Items.Add(msg);
if (scroll)
this.listBox1.TopIndex = this.listBox1.Items.Count - (int)(this.listBox1.Height / this.listBox1.ItemHeight);
this.listBox1.SelectedIndex = this.listBox1.Items.Count - 1;
}
颜色主要通过DrawItem方法进行行级重绘
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{