方法一:
| 代码如下 | 复制代码 |
|
this.listBox1.Items.Add("new line"); this.listBox1.SelectedIndex = this.listBox1.Items.Count - 1; this.listBox1.SelectedIndex = -1; |
|
在添加记录后,先选择最后一条记录,滚动条会自动到底部,再取消选择。
缺点是需两次设置选中条目,中间可能会出现反色的动画,影响美观。
方法二:
| 代码如下 | 复制代码 |
|
this.listBox1.Items.Add("new line"); this.listBox1.TopIndex = this.listBox1.Items.Count - (int)(this.listBox1.Height / this.listBox1.ItemHeight); |
|
通过计算ListBox显示的行数,设置TopIndex属性(ListBox中第一个可见项的索引)而达到目的。
方法二 plus:智能滚动
| 代码如下 | 复制代码 |
|
bool scroll = false; if(this.listBox1.TopIndex == this.listBox1.Items.Count - (int)(this.listBox1.Height / this.listBox1.ItemHeight)) scroll = true; this.listBox1.Items.Add("new line"); if (scroll) this.listBox1.TopIndex = this.listBox1.Items.Count - (int)(this.listBox1.Height / this.listBox1.ItemHeight); |
|
在添加新记录前,先计算滚动条是否在底部,从而决定添加后是否自动滚动。
罚罪1+2全80集阿里云盘全集资源链接-罚罪1+2全集高清1080P/4K阿里云盘资源下载无删减
邵氏精品禁品未删减资源在线看-必看的50部邵氏电影无删减观看入口
羞羞漫画高清最新资源-正规平台免费入口与无删减资源导航
日漫入口-官方认证安全入口与无删减日漫资源直达导航
一拳超人漫画入口-2026最新免费高清全集在线看
杨紫《生命树》1080p全40集迅雷磁力链接分享-杨紫《生命树》40集高清完整版迅雷云盘下载1080P(4k)资源