博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c# listbox使用_设计一个Windows应用程序以演示C#中ListBox的使用
阅读量:2542 次
发布时间:2019-05-11

本文共 2484 字,大约阅读时间需要 8 分钟。

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

翻译自:

c# listbox使用

转载地址:http://ecozd.baihongyu.com/

你可能感兴趣的文章
51Nod1601 完全图的最小生成树计数 Trie Prufer编码
查看>>
Codeforces 1110D. Jongmah 动态规划
查看>>
android驱动在win10系统上安装的心酸历程
查看>>
优雅的程序员
查看>>
oracle之三 自动任务调度
查看>>
Android dex分包方案
查看>>
ThreadLocal为什么要用WeakReference
查看>>
删除本地文件
查看>>
FOC实现概述
查看>>
base64编码的图片字节流存入html页面中的显示
查看>>
这个大学时代的博客不在维护了,请移步到我的新博客
查看>>
GUI学习之二十一——QSlider、QScroll、QDial学习总结
查看>>
nginx反向代理docker registry报”blob upload unknown"解决办法
查看>>
gethostbyname与sockaddr_in的完美组合
查看>>
kibana的query string syntax 笔记
查看>>
旋转变换(一)旋转矩阵
查看>>
thinkphp3.2.3 bug集锦
查看>>
[BZOJ 4010] 菜肴制作
查看>>
C# 创建 读取 更新 XML文件
查看>>
KD树
查看>>