Created
October 31, 2017 07:15
-
-
Save mrgarita/847e945fd1726ce2e6ee45961e4ee4d2 to your computer and use it in GitHub Desktop.
C#:コンボボックスの使い方
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows.Forms; | |
namespace コンボボックスの使い方 | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
// コンボボックスにアイテムを追加 | |
comboBox1.Items.Add("オレンジ"); | |
comboBox1.Items.Add("赤"); | |
comboBox1.Items.Add("黄色"); | |
comboBox1.Items.Add("緑"); | |
comboBox1.Items.Add("青"); | |
// コンボボックスを読み取り専用にする | |
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList; | |
// 初期表示 | |
label1.Text = ""; | |
comboBox1.SelectedIndex = -1; // 初期表示なし | |
} | |
private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e) | |
{ | |
string selectedItem = comboBox1.SelectedItem.ToString(); | |
label1.Text = selectedItem + "が選択されました"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment