메뉴 건너뛰기

Programing

C# 게시판

리스트사용하기

관리자2 2018.12.24 19:27 조회 수 : 150

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 ts6

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void btnAdd_Click(object sender, EventArgs e)

        {

            if(this.txtName.Text != "")

            {

                this.ltbName.Items.Add(this.txtName.Text);

                this.txtName.Text = "";

            }

        }

 

        private void btnDel_Click(object sender, EventArgs e)

        {

            this.ltbName.Items.Remove(this.txtName.Text);

            this.txtName.Text = "";

        }

 

        private void txtName_KeyPress(object sender, KeyPressEventArgs e)

        {

            if (this.txtName.Text != "" && e.KeyChar == (char)13)

            {

                this.ltbName.Items.Add(this.txtName.Text);

                this.txtName.Text = "";

            }

        }

    }

}

항목을 적고 추가를 누르거나 엔터를 치면 추가가 되고 항목을 적고 삭제를 누르면 그항목이 삭제 된다.

위로