滚动可以通过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)
{
e.DrawBackground();
if (e.I

本文介绍了如何在WinForm应用中实现ListBox控件自动滚动到底部的功能,并详细讲解了如何利用DrawItem事件来设置ListBox中每一行文字的颜色,提供了一种增强UI交互的方法。
1568

被折叠的 条评论
为什么被折叠?



