{"id":465,"date":"2010-12-21T21:19:39","date_gmt":"2010-12-21T21:19:39","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=465"},"modified":"2022-02-17T06:24:04","modified_gmt":"2022-02-17T06:24:04","slug":"menu","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/menu\/menu","title":{"rendered":"Menu"},"content":{"rendered":"<p>The main Menu is called the MenuStrip<br \/>\nMenu&#8217;s that pop up within the context of some control, for instance when you right click, use the ContextMenuStrip.<\/p>\n<h4>Creating a MenuStrip<\/h4>\n<p>Drag the menu tool onto the top of the form<\/p>\n<p>You can edit the menu contents using the properties &gt; collections (recomended for complex menu&#8217;s), or just by clicking on the bar and adding entries, then double clicking them to edit their action code<\/p>\n<h4>Adding And Removing MenuStrip Items<\/h4>\n<pre><code>\r\n\t\/\/REMOVE ANY EXISTING MENU ITEMS\r\n\tToolStripItem ^ExistingMenuItem;\r\n\twhile (recentFilesToolStripMenuItem-&gt;DropDownItems-&gt;Count)\r\n\t{\r\n\t\tExistingMenuItem = recentFilesToolStripMenuItem-&gt;DropDownItems[0];\r\n\t\trecentFilesToolStripMenuItem-&gt;DropDownItems-&gt;Remove(ExistingMenuItem);\r\n\t}\r\n\r\n\t\/\/ADD NEW MENU ITEMS\r\n\tToolStripMenuItem ^NewMnuItem;\r\n\tfor (Count = 0; Count &lt; RecentFilenamesCount; Count++)\r\n\t{\r\n\t\tNewMnuItem = gcnew ToolStripMenuItem();\t\t\/\/(Need to create new each time)\r\n\r\n\t\tTempString = RecentFilenames[Count];\r\n\t\tNewMnuItem-&gt;Text = TempString;\r\n\t\tNewMnuItem-&gt;Size = System::Drawing::Size(160, 22);\r\n\t\tNewMnuItem-&gt;Click += gcnew System::EventHandler(this, &amp;frmMain::someToolStripFileMenuRecentFile_Click);\r\n\r\n\t\trecentFilesToolStripMenuItem-&gt;DropDownItems-&gt;Add(NewMnuItem);\r\n\t}\r\n\r\n\/\/OR USE THIS FOR SINGLE ADDITION\r\n\tlaunchCCAsAdminToolStripMenuItem = gcnew System::Windows::Forms::ToolStripMenuItem();\r\n\tlaunchCCAsAdminToolStripMenuItem-&gt;Name = L\"launchCCAsAdminToolStripMenuItem\";\r\n\tlaunchCCAsAdminToolStripMenuItem-&gt;Size = System::Drawing::Size(200, 22);\r\n\tlaunchCCAsAdminToolStripMenuItem-&gt;Text = L\"Some Text\";\r\n\tlaunchCCAsAdminToolStripMenuItem-&gt;Click += gcnew System::EventHandler(this, &amp;frmMain::launchCCAsAdminToolStripMenuItem_Click);\r\n\ttoolsToolStripMenuItem-&gt;DropDownItems-&gt;Add(someToolStripMenuItem);\r\n<\/code><\/pre>\n<h4>Removing an individual item<\/h4>\n<pre><code>\r\n\ttoolsToolStripMenuItem-&gt;DropDownItems-&gt;Remove(someToolStripMenuItem);\r\n<\/code><\/pre>\n<h4>Adding An Array Of MenuStrip Items<\/h4>\n<h5>Define global array<\/h5>\n<pre><code>\r\nprivate: array&lt;System::Windows::Forms::ToolStripMenuItem^&gt; ^graphicStatusFormToolStripMenuItem;\r\n<\/code><\/pre>\n<h5>In Form Load<\/h5>\n<pre><code>\r\n\t\/\/CREATE THE ARRAY\r\n\tgraphicStatusFormToolStripMenuItem = gcnew array&lt;System::Windows::Forms::ToolStripMenuItem^&gt;(NUMBER_OF_GRAPHIC_STATUS_FORMS);\r\n\r\n\t\/\/CREATE EACH MENU ITEM\r\n\tToolStripMenuItem ^NewMnuItem;\r\n\tfor (Count = 0; Count &lt; NUMBER_OF_GRAPHIC_STATUS_FORMS; Count++)\r\n\t{\r\n\t\tNewMnuItem = gcnew ToolStripMenuItem();\t\t\/\/(Need to create new each time)\r\n\r\n\t\tNewMnuItem-&gt;Text = L\"Graphic Status \" + Convert::ToString(Count + 1);\r\n\t\tNewMnuItem-&gt;Size = System::Drawing::Size(165, 22);\r\n\t\tNewMnuItem-&gt;Click += gcnew System::EventHandler(this, &amp;frmMain::graphicStatusToolStripMenuItem_Click);\r\n\r\n\t\t\/\/Add the item to the menu\r\n\t\tthis-&gt;graphicStatusToolStripMenuItem-&gt;DropDownItems-&gt;Add(NewMnuItem);\r\n\t}\r\n<\/code><\/pre>\n<h5>In the event handler<\/h5>\n<pre><code>\r\n\tint Count;\r\n\tint FormId = 0xff;\r\n\r\n\tToolStripMenuItem ^ClickedItem = dynamic_cast&lt;ToolStripMenuItem^&gt;(sender);\r\n\tif (ClickedItem != nullptr)\r\n\t{\r\n\t\tfor (Count = 0; Count &lt; NUMBER_OF_GRAPHIC_STATUS_FORMS; Count++)\r\n\t\t{\r\n\t\t\tif (ClickedItem-&gt;Text == L\"Graphic Status \" + Convert::ToString(Count + 1))\r\n\t\t\t{\r\n\t\t\t\tFormId = Count;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\/\/EXIT IF NOT VALID\r\n\tif (FormId &gt;= NUMBER_OF_GRAPHIC_STATUS_FORMS)\r\n\t\treturn;\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The main Menu is called the MenuStrip Menu&#8217;s that pop up within the context of some control, for instance when you right click, use the ContextMenuStrip. Creating a MenuStrip Drag the menu tool onto the top of the form You can edit the menu contents using the properties &gt; collections (recomended for complex menu&#8217;s), or [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-465","post","type-post","status-publish","format-standard","hentry","category-menu"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/comments?post=465"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/465\/revisions"}],"predecessor-version":[{"id":1074,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/465\/revisions\/1074"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}