はじめに
RadioButtonコントロールは、複数の選択肢の中から一つだけを選択できるUI要素です。ラジオボタンは、互いに排他的なグループとして機能し、一度に一つのラジオボタンだけが選択状態になります。
RadioButtonのプロパティ解説
RadioButtonで使用できる主なプロパティについて紹介します。
外観に関するプロパティ
- Appearance: RadioButtonの外観を指定します。(Normal, Button)
- BackColor: RadioButtonの背景色を設定します。
- ForeColor: RadioButtonの前景色(文字色)を設定します。
- Font: RadioButtonに表示されるテキストのフォントを設定します。
- Checked: RadioButtonが選択されているかどうかを示すブール値です。
- Text: RadioButtonに表示されるテキストを設定します。
- TextAlign: RadioButton内のテキストの配置を設定します。(TopLeft, TopCenter, TopRight,MiddleLeft, MiddleCenter, MiddleRight, BottomLeft, BottomCenter, BottomRight)
- Image: RadioButtonに表示するイメージを設定します。
- ImageAlign: RadioButton内のイメージの配置を設定します。
レイアウトに関するプロパティ
- Location: RadioButtonの左上隅の座標を設定します。
- Size: RadioButtonの幅と高さを設定します。
- Anchor: RadioButtonを配置するコンテナの端との相対的な位置を設定し、コンテナのサイズ変更時にRadioButtonがどのように移動するかを制御します。
- Dock: RadioButtonをコンテナの端へドッキングさせる方法を設定します。(None, Top, Bottom, Left, Right, Fill)
- Margin: RadioButtonの周囲のマージンを設定します。
- Padding: RadioButtonの内側の余白を設定します。
その他のプロパティ
- Enabled: RadioButtonが有効かどうかを示すブール値です。無効なRadioButtonはクリックできません。
- TabIndex: Tabキーを押したときにフォーカスが移動する順序を設定します。
- TabStop: Tabキーを押したときにフォーカスが移動できるかどうかを示すブール値です。
- Tag: RadioButtonに任意のオブジェクトを関連付けることができます。
プロパティの使い方例
// RadioButtonの作成 RadioButton radioButton1 = new RadioButton(); // プロパティの設定 radioButton1.Text = "選択肢1"; radioButton1.Location = new Point(10, 10); radioButton1.Size = new Size(100, 20); radioButton1.Checked = true; // 初期状態で選択状態にする // フォームにRadioButtonを追加 this.Controls.Add(radioButton1);
まとめ
RadioButtonのプロパティを適切に設定することで、様々な種類のユーザーインタフェースを作成することができます。本記事で紹介した以外にも、RadioButtonには多くのプロパティが存在しますので、必要に応じてMSDNなどのリファレンスを参照してください。
Please follow and like us:

コメント