dir.by  
Поиск >>

Компьютер, программы
→
Windows Forms (отдельное приложение exe файл)
→
Windows Forms Controls
 Элемент 'ListBox' в Windows Forms 
посмотрели 7776 раз
ListBox это список.
Screenshot примера: 'ListBox' в Windows Forms
Как написать?
Создаем новый проект Windows Forms Application в Visual Studio 2013 и перетаскиваем элемент ListBox
Добавим код в файл Form1.cs внутрь конструктора Form1()
  C#  
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

               // добавить 1 элемент
               listBox1.Items.Add("aaa");

               // добавить много элементов
               string[] arr = { "bbb", "ccc", "ddd", "eee" };
               listBox1.Items.AddRange(arr);

               // удалить элемент по индексу
               listBox1.Items.RemoveAt(3); // удалим "ddd"

               // удалить элемент по значению
               listBox1.Items.Remove("eee");

               // получить каждый элемент из ListBox
               for (int i=0;i<listBox1.Items.Count;i++)
               {
                    string str = listBox1.Items[i].ToString();
               }
          }
     }
}
Компилируем и запускаем. Все работает!
 
← Previous topic
Creating a Windows Forms App (New)
 
Next topic →
When writing large Windows Forms applications, the MVP pattern is used
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

Новость "Черная пятница" Dreame в Беларуси – две недели скидок до 3400 рублей
 
• Creating a Windows Forms App (New)
Windows Forms Controls
• ListBox
Additional topics, questions
• When writing large Windows Forms applications, the MVP pattern is used
WWW Sites to Learn Windows Forms
• Sites to learn Windows Forms

  Ваши вопросы присылайте по почте: info@dir.by