リストボックスについて

この章ではリストボックスについて解説します。

.NET Frameworkにおいてリストボックスを表すクラスはListBoxです。
下記はリストボックスを使ったサンプルコードです。

using System;
using System.Drawing;
using System.Windows.Forms;

public class Sample
{
    public static void Main(String[] args)
    {
        Form f = new Form();
        ListBox listBox  = new ListBox();
        listBox .Location = new Point(10, 10);
        listBox.Items.Add("項目1");
        listBox.Items.Add("項目2");
        listBox.Items.Add("項目3");
        f.Controls.Add(listBox );
        Application.Run(f);
    }
}

サンプルを実行するとウィンドウが表示され、その中にリストボックスが表示されます。

ListBoxクラスの主なプロパティ

選択項目

リストボックスで選択されている項目を参照にはSelectedValueプロパティを使用します。

表示位置

リストボックスの位置を設定するにはLocationプロパティを設定します。
Locationプロパティの型はPointクラスになります。



inserted by FC2 system