using System;
using System.Windows.Forms;
namespace ListBoxExample
{
public class ListBoxDemo : Form
{
private ListBox listBox1;
public ListBoxDemo()
{
// 初始化 ListBox 控件
listBox1 = new ListBox();
listBox1.Location = new System.Drawing.Point(20, 20);
listBox1.Size = new System.Drawing.Size(200, 100);
// 添加一些示例项到 ListBox
listBox1.Items.Add("Item 1");
listBox1.Items.Add("Item 2");
listBox1.Items.Add("Item 3");
// 设置 ListBox 的选择模式为多选
listBox1.SelectionMode = SelectionMode.MultiExtended;
// 将 ListBox 添加到窗体中
this.Controls.Add(listBox1);
// 设置窗体的属性
this.Text = "ListBox Example";
this.Size = new System.Drawing.Size(300, 200);
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new ListBoxDemo());
}
}
}
System
和 System.Windows.Forms
命名空间,并定义了一个名为 ListBoxDemo
的类,该类继承自 Form
。ListBoxDemo
类的构造函数中,初始化了一个 ListBox
控件,并设置了它的位置、大小和一些示例项。listBox1.Items.Add()
方法向 ListBox
中添加了三个示例项。ListBox
的选择模式设置为 SelectionMode.MultiExtended
,允许用户进行多选。ListBox
控件添加到窗体中。Main
方法中,启动应用程序并显示窗体。上一篇:c# modbus tcp
下一篇:c#上位机开发
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站