Share via


MenuItem.Checked Özellik

Tanım

Menü öğesinin metninin yanında onay işaretinin görünüp görünmediğini belirten bir değer alır veya ayarlar.

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

Özellik Değeri

true menü öğesinin yanında onay işareti varsa; aksi takdirde , false. Varsayılan değer: false.

Özel durumlar

MenuItem üst düzey bir menüdür veya alt öğeleri vardır.

Örnekler

Aşağıdaki kod örneği, bir uygulamada durumu sağlamak için özelliğini kullanır Checked . Bu örnekte, denetimdeki metnin rengini belirtmek için bir TextBox grup menü öğesi kullanılır. Sağlanan olay işleyicisi, üç menü öğesinin Click olayı tarafından kullanılır. Her menü öğesi bir metin rengi, menuItemRed (Kırmızı), (Yeşil) menuItemGreen veya menuItemBlue (Mavi) belirtir. Olay işleyicisi, hangi menü öğesine tıklandığını belirler, seçili menü öğesine bir onay işareti yerleştirir ve formun TextBox denetiminin metin rengini değiştirir. Örnek, ad alanının System.Drawing bu kodun yerleştirildiği forma eklenmesini gerektirir. Örnek, bu örnek kodun içinde bulunduğu ve adlı textBox1forma bir TextBox eklenmesini de gerektirir.

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

Açıklamalar

Bir uygulamanın durumunu sağlamak için özelliğini menüdeki diğer menü öğeleriyle birlikte kullanabilirsiniz Checked . Örneğin, bir uygulamadaki metin için görüntülenecek yazı tipinin boyutunu belirlemek için bir öğe grubundaki menü öğesine onay işareti yerleştirebilirsiniz. Birbirini dışlayan Checked menü öğeleri grubundaki seçili menü öğesini tanımlamak için özelliğini de kullanabilirsiniz.

Not

Üst düzey menü öğeleri için bu özellik olarak ayarlanamaz true .

Şunlara uygulanır