应用场景: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);
}}
转载于:https://www.cnblogs.com/seanyan/p/11474006.html
相关资源:c# Listbox自动滚动