C#创建列表框应用程序

C#创建列表框应用程序,c#,C#,我想用一个ListBox对象在C#中创建一个windows应用程序。我需要创建一个订单与6个不同的东西要购买。有人能告诉我如何为列表框编码吗?请看一下。此MSDN页面有许多示例。查看保存项目列表的Items属性。也许google for您可以使用如下列表框: private void button1_Click(object sender, System.EventArgs e) { // Create an instance of the ListBox. ListBox list

我想用一个ListBox对象在C#中创建一个windows应用程序。我需要创建一个订单与6个不同的东西要购买。有人能告诉我如何为列表框编码吗?

请看一下。此MSDN页面有许多示例。查看保存项目列表的Items属性。

也许google for

您可以使用如下列表框:

private void button1_Click(object sender, System.EventArgs e)
{
   // 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);

   // Display the second selected item in the ListBox to the console.
   System.Diagnostics.Debug.WriteLine(listBox1.SelectedItems[1].ToString());
   // Display the index of the first selected item in the ListBox.
   System.Diagnostics.Debug.WriteLine(listBox1.SelectedIndices[0].ToString());             
}
private void按钮1\u单击(对象发送者,System.EventArgs e)
{
//创建列表框的实例。
ListBox listBox1=新建ListBox();
//设置列表框的大小和位置。
listBox1.Size=新系统.Drawing.Size(200100);
列表框1.位置=新系统.图纸.点(10,10);
//将列表框添加到表单中。
this.Controls.Add(listBox1);
//将列表框设置为在多列中显示项目。
listBox1.MultiColumn=true;
//将选择模式设置为“多个”和“扩展”。
listBox1.SelectionMode=SelectionMode.MultiExtended;
//添加项目时关闭列表框的绘制。
listBox1.BeginUpdate();
//循环浏览并向列表框添加50项。

对于(intx=1;x)来说,这是我的课的额外学分。你给它一个机会吧。在某个地方卡住,然后带着一个特定的问题回来:“这怎么会不起作用?”。