次の方法で共有


MenuItem.RadioCheck プロパティ

MenuItem がチェックされている場合、チェック マークの代わりにオプション ボタンを表示するかどうかを示す値を取得または設定します。

Public Property RadioCheck As Boolean
[C#]
public bool RadioCheck {get; set;}
[C++]
public: __property bool get_RadioCheck();public: __property void set_RadioCheck(bool);
[JScript]
public function get RadioCheck() : Boolean;public function set RadioCheck(Boolean);

プロパティ値

メニュー項目がチェックされた場合に、チェック マークの代わりにオプション ボタンが使用される場合は true 。標準のチェック マークが表示される場合は false 。既定値は false です。

解説

チェック マークは、メニュー項目グループ内の複数の項目を同時に選択できないことを意味するとは限りません。メニュー項目のチェック マークによって、複数の項目を同時に選択できないことをユーザーに示すには、このプロパティを使用します。

使用例

[Visual Basic, C#, C++] Checked プロパティを使用して、アプリケーションの状態を変更する例を次に示します。この例では、 TextBox コントロール内のテキストの色を指定するために使用される複数のメニュー項目がグループにまとめて提供されています。この例で指定されているイベント ハンドラは、3 つのメニュー項目の Click イベントによって使用されます。各メニュー項目は、 menuItemRedmenuItemGreenmenuItemBlue のいずれかの色を指定します。イベント ハンドラは、クリックされたメニュー項目を判断し、選択されたそのメニュー項目にチェック マークを付け、フォーム上の TextBox コントロール textBox1 のテキストの色を変更します。また、この例では、 RadioCheck プロパティを使用して、一度に 1 つしか選択できない複数のメニュー項目を示すために、オプション ボタンのチェック マークを使用する方法も示しています。この例は、このコードが記述されているフォームに System.Drawing 名前空間が追加されていることを前提としています。

 
' This method is called from the constructor of the form to set up the menu
' items.
Public Sub ConfigureMyMenus()
    ' Set all of these menu items to Radio-Button check marks so the user
    ' can see that only one color can be selected at a time. 
    menuItemRed.RadioCheck = True
    menuItemBlue.RadioCheck = True
    menuItemGreen.RadioCheck = True
End Sub    

' The following event handler would be connected to three menu items.
Private Sub MyMenuClick(sender As Object, e As EventArgs)
    If sender Is menuItemBlue Then
        ' Set the checkmark for the menuItemBlue menu item.
        menuItemBlue.Checked = True
        ' Uncheck the menuItemRed and menuItemGreen menu items.
        menuItemRed.Checked = False
        menuItemGreen.Checked = False
        ' Set the color of the text in the TextBox control to Blue.
        textBox1.ForeColor = Color.Blue
    Else
        If sender Is menuItemRed Then
            ' Set the checkmark for the menuItemRed menu item.
            menuItemRed.Checked = True
            ' Uncheck the menuItemBlue and menuItemGreen menu items.
            menuItemBlue.Checked = False
            menuItemGreen.Checked = False
            ' Set the color of the text in the TextBox control to Red.
            textBox1.ForeColor = Color.Red
        Else
            ' Set the checkmark for the menuItemGreen menu item.
            menuItemGreen.Checked = True
            ' Uncheck the menuItemRed and menuItemGreen menu items.
            menuItemBlue.Checked = False
            menuItemRed.Checked = False
            ' Set the color of the text in the TextBox control to Blue.
            textBox1.ForeColor = Color.Green
        End If
    End If
End Sub


[C#] 
// This method is called from the constructor of the form to set up the menu items.
public void ConfigureMyMenus()
{
   /* Set all of these menu items to Radio-Button check marks so the user can see 
      that only one color can be selected at a time. */
   menuItemRed.RadioCheck = true;
   menuItemBlue.RadioCheck = true;
   menuItemGreen.RadioCheck = true;
}

// The following event handler would be connected to three menu items.
private void MyMenuClick(Object sender, EventArgs e)
{
   if(sender == menuItemBlue)
   {
      // Set the checkmark for the menuItemBlue menu item.
      menuItemBlue.Checked = true;
      // Uncheck the menuItemRed and menuItemGreen menu items.
      menuItemRed.Checked = false;
      menuItemGreen.Checked = false;
      // Set the color of the text in the TextBox control to Blue.
      textBox1.ForeColor = Color.Blue;
   }
   else if(sender == menuItemRed)
   {
      // Set the checkmark for the menuItemRed menu item.
      menuItemRed.Checked = true;
      // Uncheck the menuItemBlue and menuItemGreen menu items.
      menuItemBlue.Checked = false;
      menuItemGreen.Checked = false;
      // Set the color of the text in the TextBox control to Red.
      textBox1.ForeColor = Color.Red;
   }
   else
   {
     // Set the checkmark for the menuItemGreen menu item.
      menuItemGreen.Checked = true;
      // Uncheck the menuItemRed and menuItemGreen menu items.
      menuItemBlue.Checked = false;
      menuItemRed.Checked = false;
      // Set the color of the text in the TextBox control to Blue.
      textBox1.ForeColor = Color.Green;
   }
}


[C++] 
// This method is called from the constructor of the form to set up the menu items.
public:
void ConfigureMyMenus()
{
   /* Set all of these menu items to Radio-Button check marks so the user can see 
      that only one color can be selected at a time. */
   menuItemRed->RadioCheck = true;
   menuItemBlue->RadioCheck = true;
   menuItemGreen->RadioCheck = true;
}

// The following event handler would be connected to three menu items.
private:
void MyMenuClick(Object* sender, EventArgs* /*e*/)
{
   if(sender == menuItemBlue)
   {
      // Set the checkmark for the menuItemBlue menu item.
      menuItemBlue->Checked = true;
      // Uncheck the menuItemRed and menuItemGreen menu items.
      menuItemRed->Checked = false;
      menuItemGreen->Checked = false;
      // Set the color of the text in the TextBox control to Blue.
      textBox1->ForeColor = Color::Blue;
   }
   else if(sender == menuItemRed)
   {
      // Set the checkmark for the menuItemRed menu item.
      menuItemRed->Checked = true;
      // Uncheck the menuItemBlue and menuItemGreen menu items.
      menuItemBlue->Checked = false;
      menuItemGreen->Checked = false;
      // Set the color of the text in the TextBox control to Red.
      textBox1->ForeColor = Color::Red;
   }
   else
   {
      // Set the checkmark for the menuItemGreen menu item.
      menuItemGreen->Checked = true;
      // Uncheck the menuItemRed and menuItemGreen menu items.
      menuItemBlue->Checked = false;
      menuItemRed->Checked = false;
      // Set the color of the text in the TextBox control to Blue.
      textBox1->ForeColor = Color::Green;
   }
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

MenuItem クラス | MenuItem メンバ | System.Windows.Forms 名前空間 | Checked