-
ComboBoxC#/WindowForm 2022. 4. 6. 10:55
디자인 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 _026_ComboBox { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { ComboBox comboBox = (ComboBox)sender; lblRestaurant.Text = "모임 장소: "+comboBox.SelectedItem.ToString(); } private void button1_Click(object sender, EventArgs e) { if (comboBox1.Text != "") { comboBox1.Items.Add(comboBox1.Text); lblRestaurant.Text = "추가되었습니다"; } } private void button2_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex>0) { lblRestaurant.Text = comboBox1.SelectedItem.ToString() + "삭제되었습니다"; comboBox1.Items.Remove(comboBox1.SelectedItem); } } private void Form1_Load(object sender, EventArgs e) { } } }
comboBox1.Items.Add(comboBox1.Text); 콤보박스에 추가
comboBox1.Items.Remove(comboBox1.SelectedItem); 콤보박스에서 삭제
실행화면 'C# > WindowForm' 카테고리의 다른 글
ComboBox를 사용한 학점 계산기 (0) 2022.04.06 ListBox (0) 2022.04.06 C# 라디오버튼과 그룹박스 (0) 2022.03.30 C# 체크박스 (0) 2022.03.30 C# Flag (0) 2022.03.30