Page Top

Winform ListBox输出信息并自动滚动至底部

应用场景:ListBox作为软件信息的输出框。

//ListBox输出信息
internal void SetListBoxMessage(string str)
{
   if (this.MessageListBox.InvokeRequired)
   {
      Action<string> actionDelegate = (x) =>
      {
         MessageListBox.Items.Add(str);
         MessageListBox.TopIndex = MessageListBox.Items.Count - (int)(MessageListBox.Height / MessageListBox.ItemHeight);
      };
      this.MessageListBox.Invoke(actionDelegate, str);
   }
   else
   {
      MessageListBox.Items.Add(str);
      MessageListBox.TopIndex = MessageListBox.Items.Count - (int)(MessageListBox.Height / MessageListBox.ItemHeight);
   }
}

 

posted @ 2019-09-06 13:20  抹茶大虾球丶  阅读(718)  评论(0编辑  收藏  举报