c# listbox使用_设计一个Windows应用程序以演示C#中ListBox的使用

news/2024/7/9 23:40:53 标签: java, python, linux, web, vue

c# listbox使用

Following operations are performing on the ListBox:

在ListBox上执行以下操作:

  1. Add

  2. Remove

    去掉

  3. Clear

    明确

  4. Get selected items

    获取所选项目

  5. etc...

    等等...

Follow controls are using in the application:

在应用程序中使用以下控件:

  • txtInput (TextBox) : To take user input.

    txtInput (TextBox):接受用户输入。

  • lblCount (Label) : To show count of list-box items.

    lblCount (标签):显示列表框项目的计数。

  • lstItem (ListBox) : List-box to contain list of items.

    lstItem (ListBox):包含项目列表的列表框。

  • btnAdd (Button) : To add entered item into list.

    btnAdd (按钮):将输入的项目添加到列表中。

  • btnRemove (Button) : To remove selected item from list.

    btnRemove (按钮):从列表中删除选定的项目。

  • btnShow (Button) : To show selected item in message-box.

    btnShow (按钮):在消息框中显示选定的项目。

  • btnClear (Button) : To clear complete list.

    btnClear (按钮):清除完整列表。

Example (form design):

示例(表单设计):

List Box Example in C#

C# Source Code:

C#源代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MyWinApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            lstItem.Items.Add(txtInput.Text);
            txtInput.Text = "";
            lblCount.Text = "Count: " + lstItem.Items.Count;
        }

        private void btnRmv_Click(object sender, EventArgs e)
        {
            lstItem.Items.RemoveAt(lstItem.SelectedIndex);
            lblCount.Text = "Count: " + lstItem.Items.Count;
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            MessageBox.Show(lstItem.SelectedItem.ToString());
        }

        private void btnClr_Click(object sender, EventArgs e)
        {
            lstItem.Items.Clear();
            lblCount.Text = "Count: " + lstItem.Items.Count;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            lblCount.Text = "Count: " + lstItem.Items.Count;
        }
    }
}

In the above code, we used button click events for performing tasks. We used following methods:

在上面的代码中,我们使用了按钮单击事件来执行任务。 我们使用以下方法:

  1. Listbox.Itmes.Add(text)

    Listbox.Itmes.Add(文本)

  2. Listbox.Itmes.RemoveAt(index)

    Listbox.Itmes.RemoveAt(index)

  3. Listbox.Itmes.Clear()

    Listbox.Itmes.Clear()

We used some properties like:

我们使用了一些属性,例如:

  1. lstItem.Items.Count

    lstItem.Items.Count

  2. lstItem.SelectedIndex

    lstItem.SelectedIndex

  3. lstItem.SelectedItem

    lstItem.SelectedItem

翻译自: https://www.includehelp.com/dot-net/listbox-example-in-c-sharp.aspx

c# listbox使用


http://www.niftyadmin.cn/n/1255824.html

相关文章

第一阶段 14多线程

多线程 1.1 多线程介绍 进程:进程指正在运行的程序。确切的来说,当一个程序进入内存运行,即变成一个进程,进程是处于运行过程中的程序,并且具有一定独立功能。 线程:线程是进程中的一个执行单元&#x…

IIS配置httpcompression,压缩json文本提升性能

目录 1、发现 2、测试 3、配置方法 1、发现 IIS是基于Http协议进行数据传输的,我发现在项目中大概使用Get/Post返回Json,而Json并没有使用压缩。 如下图,响应的头部,也就是说IIS是可以支持Compression的。 2、测试 测试数据…

不可不知的表达式树(1)Expression初探

说起Lambda表达式,大家基本都很熟悉了,而表达式树(Expression Trees),则属于80%的工作中往往都用不到的那种技术,所以即便不是什么新技术,很多人对其理解都并不透彻。此文意图从表达式树基本技术…

C ++ | 用setter和getter方法创建一个类

In the below program, we are creating a C program to create a class with setter and getter methods. 在下面的程序中&#xff0c;我们正在创建一个C 程序&#xff0c;以使用setter和getter方法创建一个类 。 #include <iostream>using namespace std;// class def…

深入计算机系统:1.1 Information Is Bits + Context(1.1 信息就是位+的上下文)

信息就是位的上下文 从C语言的生命周期源头说起&#xff0c;结合列举的简单C语言程序的Main函数&#xff0c;底层都是一串由0和1组成的比特&#xff0c;每8位组成一个字节&#xff0c;每个字节都代表着这段程序的字符&#xff0c;每个字符的对应关系大多由ASCII组合成&#xff…

开源软件 许可证密钥_免费和开源软件2中的重要许可证

开源软件 许可证密钥Apache许可证 (The Apache License) Released by the Apache Software Foundation (ASF), The Apache License is an open-source software license. Its a popular and broadly used license supported by a solid community. The Apache License permits …

SQL:测试比较exists和in的执行效率

目录 1.select 具体字段和select *的效率 2.exists 和 in的效率(关联字段都是索引列) 任务表(Task)中&#xff0c;大概有30列&#xff0c;大概有35万的数据量。 1.select 具体字段和select *的效率 set statistics time onselect * from x.dbo.et_taskselect id,name from…

c程序实现整数转换为字符串_C ++程序将数字字符串转换为整数

c程序实现整数转换为字符串Write a recursive function to convert a given string into the number it represents. That is input will be a numeric string that contains only numbers, you need to convert the string into corresponding integer and return the answer.…