一、属性
// Create an instance of the ListBox.
ListBox listBox1 = new ListBox();
// Set the size and location of the ListBox.
listBox1.Size = new System.Drawing.Size(200, 100);
listBox1.Location = new System.Drawing.Point(10, 10);
// Add the ListBox to the form.
this.Controls.Add(listBox1);
// Set the ListBox to display items in multiple columns.
listBox1.MultiColumn = true ;
// Set the selection mode to multiple and extended.
listBox1.SelectionMode = SelectionMode.MultiExtended ;
// Shutdown the painting of the ListBox as items are added.
listBox1.BeginUpdate();//如果不指定的话,每次添加一个项都要绘制一次,降低了性能
// Loop through and add 50 items to the ListBox.
for (int x = 1; x <= 50; x++)
{
listBox1.Items.Add("Item " + x.ToString());
}
// Allow the ListBox to repaint and display the new items.
listBox1.EndUpdate();
// Select three items from the ListBox.
listBox1.SetSelected(1, true);
listBox1.SetSelected(3, true);
listBox1.SetSelected(5, true);
1、MultiColumn-可多列排布,建议设为false(即多行,辅助以垂直滚动条)
2、垂直滚动条-ScrollAlwaysVisible
二、语法(控件名为listBox1)
for (int x = 1; x < 20; x++)
{
listBox1.Items.Add("Item\t" + x.ToString());
}
可直接添加。