MenuItem.Checked プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > MenuItem.Checked プロパティの意味・解説 

MenuItem.Checked プロパティ

メニュー項目のテキストの横にチェック マーク表示するかどうかを示す値を取得または設定します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

例外例外
例外種類条件

ArgumentException

MenuItem はトップレベル メニューであるか、子があります

解説解説
使用例使用例

Checked プロパティ使用してアプリケーションの状態を示すコード例次に示します。この例では、グループにまとめた複数メニュー項目を使用してTextBox コントロール内のテキストの色を指定します指定されているイベント ハンドラは、3 つのメニュー項目の Click イベントによって使用されます。メニュー項目は、テキストの色として menuItemRed (赤)、menuItemGreen (緑)、menuItemBlue (青) のいずれか指定しますイベント ハンドラは、クリックされたメニュー項目を判断し選択されたそのメニュー項目にチェック マーク付けフォームTextBox コントロール内にあるテキストの色を変更します。この例では、このコード記述されているフォームSystem.Drawing 名前空間追加されている必要があります。さらに、そのフォームtextBox1 という名前の TextBox追加されている必要もあります

' 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

// 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;
    }
 }

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.Equals( menuItemBlue)) {
        // Set the checkmark for the menuItemBlue menu item.
        menuItemBlue.set_Checked(true);

        // Uncheck the menuItemRed and menuItemGreen menu items.
        menuItemRed.set_Checked(false);
        menuItemGreen.set_Checked(false);

        // Set the color of the text in the TextBox control to Blue.
        textBox1.set_ForeColor(Color.get_Blue());
    }
    else {
        if (sender.Equals( menuItemRed)) {
            // Set the checkmark for the menuItemRed menu item.
            menuItemRed.set_Checked(true);

            // Uncheck the menuItemBlue and menuItemGreen menu items.
            menuItemBlue.set_Checked(false);
            menuItemGreen.set_Checked(false);

            // Set the color of the text in the TextBox control to Red.
            textBox1.set_ForeColor(Color.get_Red());
        }
        else {
            // Set the checkmark for the menuItemGreen.
            menuItemGreen.set_Checked(true);

            // Uncheck the menuItemRed and menuItemBlue menu items.
            menuItemBlue.set_Checked(false);
            menuItemRed.set_Checked(false);

            // Set the color of the text in the TextBox control to Blue.
            textBox1.set_ForeColor(Color.get_Green());
        }
    }
} //MyMenuClick 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からMenuItem.Checked プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からMenuItem.Checked プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からMenuItem.Checked プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「MenuItem.Checked プロパティ」の関連用語

MenuItem.Checked プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



MenuItem.Checked プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS