MenuItem.Checked 속성

정의

메뉴 항목의 텍스트 옆에 확인 표시가 나타나는지를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool Checked { bool get(); void set(bool value); };
public bool Checked { get; set; }
member this.Checked : bool with get, set
Public Property Checked As Boolean

속성 값

메뉴 항목 옆에 확인 표시가 있으면 true이고, 그렇지 않으면 false입니다. 기본값은 false입니다.

예외

MenuItem이 최상위 메뉴이거나 자식을 갖는 경우

예제

다음 코드 예제에서는 Checked 속성을 애플리케이션의 상태를 지정 합니다. 이 예제에서는 그룹 메뉴 항목을 텍스트의 색 지정 되는 TextBox 제어 합니다. 제공 된 이벤트 처리기에서 사용 되는 Click 세 가지 메뉴 항목의 이벤트입니다. 각 메뉴 항목 텍스트 색을 지정 menuItemRed (빨간색) menuItemGreen (녹색) 또는 menuItemBlue (파란색). 이벤트 처리기는 메뉴 항목 클릭 했을 결정 선택한 메뉴 항목에 확인 표시를 배치 하 고 폼의 텍스트 색을 변경 TextBox 제어 합니다. 이 예제에서는 System.Drawing 네임 스페이스가이 코드에 배치 된 폼에 추가 되었습니다. 또한이 예제는 TextBox 이라고 하는이 예제 코드에는 폼에 추가 되었습니다 textBox1합니다.

private:
   // The following event handler would be connected to three menu items.
   void MyMenuClick( Object^ sender, EventArgs^ e )
   {
      // Determine if clicked menu item is the Blue menu item.
      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.
         menuItemGreen->Checked = true;
         // Uncheck the menuItemRed and menuItemBlue menu items.
         menuItemBlue->Checked = false;
         menuItemRed->Checked = false;
         // Set the color of the text in the TextBox control to Blue.
         textBox1->ForeColor = Color::Green;
      }
   }
// The following event handler would be connected to three menu items.
 private void MyMenuClick(Object sender, EventArgs e)
 {
    // Determine if clicked menu item is the Blue menu item.
    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.
       menuItemGreen.Checked = true;
       // Uncheck the menuItemRed and menuItemBlue menu items.
       menuItemBlue.Checked = false;
       menuItemRed.Checked = false;
       // Set the color of the text in the TextBox control to Blue.
       textBox1.ForeColor = Color.Green;
    }
 }
' The following event handler would be connected to three menu items.
Private Sub MyMenuClick(sender As Object, e As EventArgs)
    ' Determine if clicked menu item is the Blue menu item.
    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.
            menuItemGreen.Checked = True
            ' Uncheck the menuItemRed and menuItemBlue 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

설명

사용할 수는 Checked 애플리케이션에 대 한 상태를 제공 하는 메뉴에서 다른 메뉴 항목과 함께에서 속성입니다. 예를 들어 그룹의 텍스트는 애플리케이션에 대해 표시할 글꼴 크기를 식별 하는 항목의 메뉴 항목에 확인 표시를 배치할 수 있습니다. 사용할 수도 있습니다는 Checked 상호 배타적인 메뉴 항목의 그룹에 선택한 메뉴 항목을 식별 하는 속성입니다.

참고

이 속성 설정할 수 없습니다 true 최상위 메뉴 항목에 대 한 합니다.

적용 대상