ListBoxは、リストボックスコントロールを扱うクラス・・・。
ListBox クラス (System.Windows.Forms)
Form1のロード時に、アイテムを3つ追加しておき、button1を押したら選択されているアイテムのテキストを表示するようにする・・・。
を選択し、
このように配置・・・。
Form1のLoadイベントをダブルクリックして、
listBox1.Itemsがアイテムのコレクション・・・。
listBox1.Items.Addでアイテムを追加・・・。
今回は、文字列"abc", "def", "ghi"を追加・・・。
button1も配置しておく・・・。
button1が押された時、
listBox1.SelectedItemに選択されたアイテムが格納されている・・・。
文字列をアイテムとして追加したので、object型からstring型にキャストして、それをMessageBoxで表示・・・。
"def"を選択して、button1を押すと、
"def"・・・。
"abc"を選択して、button1を押すと、
"abc"・・・。
"ghi"を選択して、button1を押すと、
"ghi"・・・。
Sample/Program.cs at master · bg1bgst333/Sample · GitHub
Sample/Form1.cs at master · bg1bgst333/Sample · GitHub
Sample/Form1.Designer.cs at master · bg1bgst333/Sample · GitHub