1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

C# - ComboBoxのサンプル コードべた書き(Visual Studio不使用)

Last updated at Posted at 2020-10-26

目次: C# - Windows Formsでよく使うコントロールたち (Visual Studioなし環境向け) - Qiita

画面キャプチャ

image.png

テンプレ


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

class ComboBoxSample : Form
{
    ComboBox cmb;

    ComboBoxSample()
    {
        ClientSize = new Size(300, 100);
        
        Controls.Add(cmb = new ComboBox(){
            Location = new Point(0, 0),
            Width = 80,
            DropDownStyle = ComboBoxStyle.DropDownList, // 直接編集不可設定
            FormattingEnabled = true, // 頂いたコメントを受けて追加しました!
        });
        cmb.Items.AddRange(new string[]{"未選択","出勤","直行","不帰","不在"});
        cmb.SelectedIndex = 0;

        cmb.TextChanged += Cmb_TextChanged;
    }

    void Cmb_TextChanged(object sender, EventArgs e)
    {
        Text = cmb.Text;
    }

    [STAThread]
    static void Main()
    {
        Application.Run(new ComboBoxSample());
    }
}

参考サイト

1
3
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?