다음을 통해 공유


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

속성 값

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

예외

MenuItem 최상위 메뉴이거나 자식 메뉴입니다.

예제

다음 코드 예제에서는 애플리케이션에서 Checked 상태를 제공 하는 속성을 사용 합니다. 이 예제에서는 메뉴 항목 그룹을 사용하여 컨트롤의 텍스트 색을 TextBox 지정합니다. 제공된 이벤트 처리기는 세 가지 메뉴 항목의 Click 이벤트에서 사용됩니다. 각 메뉴 항목은 텍스트 색( menuItemRed 빨강), (녹색) menuItemGreen 또는 menuItemBlue (파랑)을 지정합니다. 이벤트 처리기는 클릭한 메뉴 항목을 결정하고, 선택한 메뉴 항목에 확인 표시를 배치하고, 폼 컨트롤의 TextBox 텍스트 색을 변경합니다. 이 예제에서는 네임스페이 System.Drawing 스를 이 코드가 배치된 양식에 추가해야 합니다. 이 예제에서는 이 예제 코드의 TextBox 이름이 textBox1지정된 폼에 A를 추가해야 합니다.

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 수 없습니다.

적용 대상