方法一:
代码如下 | 复制代码 |
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); |
在添加新记录前,先计算滚动条是否在底部,从而决定添加后是否自动滚动。
一亿小目标手游
如果让你的人生从来,你可以像王健林一样霸气的表示一亿小目标吗
一亿小目标手机版2019
一亿小目标手机版2019趣味休闲模拟游戏,玩家在游戏中将会通
巴啦啦梦幻餐厅
巴啦啦梦幻餐厅是一款充满魔幻色彩的二次元模拟经营手游,游戏界
恋爱进行时九游版
恋爱进行时九游版是一款以模拟恋爱玩法为核心的角色扮演手游,精
皇室对决fr(Null’s Royale)
皇室对决fr,即皇室战争的私服变态版本,在该版本中玩家能够拥