MenuItem.Checked プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

/** @property */ public boolean get_Checked () /** @property */ public void set_Checked (boolean value)
メニュー項目の隣にチェック マークがある場合は true。それ以外の場合は false。既定値は false です。


メニュー内のその他のメニュー項目と組み合わせて Checked プロパティを使用すると、アプリケーションの状態を示すことができます。たとえば、メニュー項目のグループ内にある 1 つの項目にチェック マークを付け、アプリケーションのテキスト表示に使用するフォントのサイズを示すことができます。Checked プロパティを使用すると、一度に 1 つしか選択できない複数のメニュー項目の中で、選択されているメニュー項目を識別できます。
![]() |
---|

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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からMenuItem.Checked プロパティを検索する場合は、下記のリンクをクリックしてください。

- MenuItem.Checked プロパティのページへのリンク