MenuItem.Checked Vlastnost

Definice

Získá nebo nastaví hodnotu označující, zda se vedle textu položky nabídky zobrazí značka zaškrtnutí.

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

Hodnota vlastnosti

truepokud je vedle položky nabídky značka zaškrtnutí; v opačném případě . false Výchozí formát je false.

Výjimky

Je MenuItem nabídka nejvyšší úrovně nebo má podřízené položky.

Příklady

Následující příklad kódu používá Checked vlastnost k poskytnutí stavu v aplikaci. V tomto příkladu se skupina položek nabídky používá k určení barvy textu v ovládacím TextBox prvku. Zadaná obslužná rutina události je používána událostí Click tří položek nabídky. Každá položka nabídky určuje barvu textu ( menuItemRed Červená), menuItemGreen (Zelená) nebo menuItemBlue (Modrá). Obslužná rutina události určuje, na kterou položku nabídky bylo kliknuto, zaškrtne vybranou položku nabídky a změní barvu textu ovládacího prvku formuláře TextBox . Příklad vyžaduje, aby System.Drawing obor názvů byl přidán do formuláře, ve které je tento kód umístěn. Příklad také vyžaduje, aby TextBox byl přidán do formuláře, ve které je tento ukázkový kód umístěn s názvem 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

Poznámky

Vlastnost můžete použít Checked v kombinaci s dalšími položkami nabídky v nabídce k zadání stavu aplikace. Zaškrtnutím položky nabídky ve skupině položek můžete například určit velikost písma, které se má zobrazit pro text v aplikaci. Vlastnost můžete použít Checked také k identifikaci vybrané položky nabídky ve skupině vzájemně se vylučujíných položek nabídky.

Poznámka

Tuto vlastnost nelze nastavit na true pro položky nabídky nejvyšší úrovně.

Platí pro