private void ShowMenu(ToolStripMenuItem toolStripItem) { if (toolStripItem != null) { this.ShowMenu(toolStripItem.OwnerItem as ToolStripMenuItem); toolStripItem.ShowDropDown(); } }
private void ServiceMenuItem_MouseHover(object sender, EventArgs e) { ServiceMenuItem.DropDownItems.Clear(); if (_service.IsRunning) { ServiceMenuItem.DropDownItems.Add(RestartServiceMenuItem); ServiceMenuItem.DropDownItems.Add(StopServiceMenuItem); } else { ServiceMenuItem.DropDownItems.Add(StartServiceMenuItem); } ServiceMenuItem.ShowDropDown(); }
private void TestMenuFontCorrect(IEnumerable toolStripItems) { foreach (ToolStripItem item in toolStripItems) { if (item is ToolStripSeparator) { continue; } Assert.AreEqual(Program.DefaultFont, item.Font, "Incorrect font for menu item:" + item.Text); ToolStripMenuItem menuItem = item as ToolStripMenuItem; if (menuItem != null && menuItem.Enabled) { menuItem.ShowDropDown(); TestMenuFontCorrect(menuItem.DropDownItems); } } }
private bool CheckMenuItem(ToolStripMenuItem MenuItem, string TypeName, bool ShowRoot) { if (((MyTag)MenuItem.Tag).NameSpase + "." + ((MyTag)MenuItem.Tag).Class == TypeName) { MenuItem.Select(); return(true); } foreach (ToolStripMenuItem item in MenuItem.DropDown.Items) { if (CheckMenuItem(item, TypeName, ShowRoot)) { if (!ShowRoot) { MenuItem.ShowDropDown(); } return(true); } } //i = null; return(false); }
private void port_item_click(object sender, EventArgs args) { ToolStripMenuItem port_item = (ToolStripMenuItem)sender; //videoSourcePlayer_jqcl.Stop(); string[] names = SerialPort.GetPortNames(); foreach (string port in names) { if (port_item.Text == port.ToString()) { try { serialPort.Close(); serialPort.PortName = port_item.Text;//串口参数设置 serialPort.BaudRate = Convert.ToInt32("115200"); serialPort.DataBits = 8; serialPort.Parity = Parity.None; serialPort.StopBits = StopBits.One; serialPort.Open(); PortCheck(sender); //shezhi.show(); //toolstripmenuitem ts = (toolstripmenuitem)contextmenustrip1.items[7]; port_item.ShowDropDown(); } catch { MessageBox.Show("串口分身失败,请关掉占用该串口的软件", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } } } }
private void HandleURLFields() { #region URL context menu tsmiOpen.Text = KPRes.OpenCmd; tsmiOpen.Image = (Image)Program.Resources.GetObject("B16x16_FTP"); tsmiOpen.Click += OnOpenUrl; ctxOpenWith.Items.Insert(0, tsmiOpen); Dictionary <string, string> translations = Program.Translation.SafeGetStringTableDictionary("KeePass.Forms.MainForm.m_ctxPwList"); string translated = string.Empty; if (translations.TryGetValue("m_ctxEntryCopyUrl", out translated)) { tsmiCopy.Text = translated; } else { tsmiCopy.Text = KPRes.Copy; } tsmiCopy.Image = (Image)Program.Resources.GetObject("B16x16_EditCopyUrl"); tsmiCopy.Click += OnCopyUrl; ctxOpenWith.Items.Insert(1, tsmiCopy); #region Add additional "Open with" entries ToolStripMenuItem tsmiOpenWith = new ToolStripMenuItem(); m_dynOpenUrl = new OpenWithMenu(tsmiOpenWith); //Show dropdown to have the entries created try { //Use reflection first //Use 'ShowDropDown' as fallback, won't work on Mono MethodInfo mi_OnMenuOpening = m_dynOpenUrl.GetType().GetMethod("OnMenuOpening", BindingFlags.Instance | BindingFlags.NonPublic); if (mi_OnMenuOpening != null) { mi_OnMenuOpening.Invoke(m_dynOpenUrl, new object[] { null, null }); } else { tsmiOpenWith.ShowDropDown(); tsmiOpenWith.HideDropDown(); } } catch { } while (tsmiOpenWith.DropDownItems.Count > 0) { ToolStripItem x = tsmiOpenWith.DropDownItems[0]; tsmiOpenWith.DropDownItems.Remove(x); if (!string.IsNullOrEmpty(m_pcadata.URL2) && (x is ToolStripMenuItem)) { ToolStripMenuItem newItem = new ToolStripMenuItem(x.Text, x.Image); newItem.Tag = x.Tag; newItem.Click += OnOpenUrl; x = newItem; } ctxOpenWith.Items.Add(x); } ; tsmiOpenWith.Dispose(); #endregion #endregion lURL.Links.Clear(); lURL.Text = KPRes.Url + ": " + KPRes.Empty; if (!string.IsNullOrEmpty(m_pcadata.URL)) { string url = CompileUrl(m_pcadata.URL); lURL.Links.Add(KPRes.Url.Length + 2, m_pcadata.URL.Length, m_pcadata.URL); lURL.Text = KPRes.Url + ": " + GetDisplayUrl(m_pcadata.URL, 60); } lURL2.Links.Clear(); lURL2.Text = KPRes.Url + ": "; tbURL2.Left = lURL2.Left + lURL2.Width; tbURL2.Width = ClientSize.Width - tbURL2.Left - lURL2.Left; if (!string.IsNullOrEmpty(m_pcadata.URL2)) { tbURL2.Text = m_pcadata.URL2; } }
public static ToolStripItem[] RecentMenu(this RecentFiles recent, Action <string> loadFileCallback, bool autoload = false, bool romloading = false) { var items = new List <ToolStripItem>(); if (recent.Empty) { var none = new ToolStripMenuItem { Enabled = false, Text = "None" }; items.Add(none); } else { foreach (var filename in recent) { string caption = filename; string path = filename; string physicalPath = filename; bool crazyStuff = true; //sentinel for newer format OpenAdvanced type code if (romloading) { if (filename.StartsWith("*")) { var oa = OpenAdvancedSerializer.ParseWithLegacy(filename); caption = oa.DisplayName; crazyStuff = false; if (oa is OpenAdvanced_OpenRom) { crazyStuff = true; physicalPath = ((oa as OpenAdvanced_OpenRom).Path); } } } //TODO - do TSMI and TSDD need disposing? yuck var item = new ToolStripMenuItem { Text = caption }; items.Add(item); item.Click += (o, ev) => { loadFileCallback(path); }; var tsdd = new ToolStripDropDownMenu(); if (crazyStuff) { //TODO - use standard methods to split filename (hawkfile acquire?) var hf = new HawkFile(); hf.Parse(physicalPath); bool canExplore = true; if (!File.Exists(hf.FullPathWithoutMember)) { canExplore = false; } if (canExplore) { //make a menuitem to show the last modified timestamp var timestamp = File.GetLastWriteTime(hf.FullPathWithoutMember); var tsmiTimestamp = new ToolStripLabel { Text = timestamp.ToString() }; tsdd.Items.Add(tsmiTimestamp); tsdd.Items.Add(new ToolStripSeparator()); if (hf.IsArchive) { //make a menuitem to let you copy the path var tsmiCopyCanonicalPath = new ToolStripMenuItem { Text = "&Copy Canonical Path" }; tsmiCopyCanonicalPath.Click += (o, ev) => { System.Windows.Forms.Clipboard.SetText(physicalPath); }; tsdd.Items.Add(tsmiCopyCanonicalPath); var tsmiCopyArchivePath = new ToolStripMenuItem { Text = "Copy Archive Path" }; tsmiCopyArchivePath.Click += (o, ev) => { System.Windows.Forms.Clipboard.SetText(hf.FullPathWithoutMember); }; tsdd.Items.Add(tsmiCopyArchivePath); var tsmiOpenArchive = new ToolStripMenuItem { Text = "Open &Archive" }; tsmiOpenArchive.Click += (o, ev) => { System.Diagnostics.Process.Start(hf.FullPathWithoutMember); }; tsdd.Items.Add(tsmiOpenArchive); } else { //make a menuitem to let you copy the path var tsmiCopyPath = new ToolStripMenuItem { Text = "&Copy Path" }; tsmiCopyPath.Click += (o, ev) => { System.Windows.Forms.Clipboard.SetText(physicalPath); }; tsdd.Items.Add(tsmiCopyPath); } tsdd.Items.Add(new ToolStripSeparator()); //make a menuitem to let you explore to it var tsmiExplore = new ToolStripMenuItem { Text = "&Explore" }; string explorePath = "\"" + hf.FullPathWithoutMember + "\""; tsmiExplore.Click += (o, ev) => { System.Diagnostics.Process.Start("explorer.exe", "/select, " + explorePath); }; tsdd.Items.Add(tsmiExplore); var tsmiCopyFile = new ToolStripMenuItem { Text = "Copy &File" }; var lame = new System.Collections.Specialized.StringCollection(); lame.Add(hf.FullPathWithoutMember); tsmiCopyFile.Click += (o, ev) => { System.Windows.Forms.Clipboard.SetFileDropList(lame); }; tsdd.Items.Add(tsmiCopyFile); var tsmiTest = new ToolStripMenuItem { Text = "&Shell Context Menu" }; tsmiTest.Click += (o, ev) => { var si = new GongSolutions.Shell.ShellItem(hf.FullPathWithoutMember); var scm = new GongSolutions.Shell.ShellContextMenu(si); var tsddi = o as ToolStripDropDownItem; tsddi.Owner.Update(); scm.ShowContextMenu(tsddi.Owner, new System.Drawing.Point(0, 0)); }; tsdd.Items.Add(tsmiTest); tsdd.Items.Add(new ToolStripSeparator()); } else { //make a menuitem to show the last modified timestamp var tsmiMissingFile = new ToolStripLabel { Text = "-Missing-" }; tsdd.Items.Add(tsmiMissingFile); tsdd.Items.Add(new ToolStripSeparator()); } } //crazystuff //in any case, make a menuitem to let you remove the item var tsmiRemovePath = new ToolStripMenuItem { Text = "&Remove" }; tsmiRemovePath.Click += (o, ev) => { recent.Remove(path); }; tsdd.Items.Add(tsmiRemovePath); ////experiment of popping open a submenu. doesnt work well. //item.MouseDown += (o, mev) => //{ // if (mev.Button != MouseButtons.Right) return; // //location of the menu containing this item that was just rightclicked // var pos = item.Owner.Bounds.Location; // //the offset within that menu of this item // var tsddi = item as ToolStripDropDownItem; // pos.Offset(tsddi.Bounds.Location); // //the offset of the click // pos.Offset(mev.Location); // //tsdd.OwnerItem = item; //has interesting promise, but breaks things otherwise // tsdd.Show(pos); //}; //just add it to the submenu for now. seems to work well enough, even though its a bit odd item.MouseDown += (o, mev) => { if (mev.Button != MouseButtons.Right) { return; } if (item.DropDown != null) { item.DropDown = tsdd; } item.ShowDropDown(); }; } } items.Add(new ToolStripSeparator()); var clearitem = new ToolStripMenuItem { Text = "&Clear", Enabled = !recent.Frozen }; clearitem.Click += (o, ev) => recent.Clear(); items.Add(clearitem); var freezeitem = new ToolStripMenuItem { Text = recent.Frozen ? "&Unfreeze" : "&Freeze" }; freezeitem.Click += (o, ev) => recent.Frozen ^= true; items.Add(freezeitem); if (autoload) { var auto = new ToolStripMenuItem { Text = "&Autoload", Checked = recent.AutoLoad }; auto.Click += (o, ev) => recent.ToggleAutoLoad(); items.Add(auto); } var settingsitem = new ToolStripMenuItem { Text = "&Recent Settings..." }; settingsitem.Click += (o, ev) => { using (var prompt = new InputPrompt { TextInputType = InputPrompt.InputType.Unsigned, Message = "Number of recent files to track", InitialValue = recent.MAX_RECENT_FILES.ToString() }) { var result = prompt.ShowDialog(); if (result == DialogResult.OK) { int val = int.Parse(prompt.PromptText); if (val > 0) { recent.MAX_RECENT_FILES = val; } } } }; items.Add(settingsitem); return(items.ToArray()); }
private void TimeGraph_FormClosing(object sender, FormClosingEventArgs e) { timerGraphToolStripMenuItem.ShowDropDown(); timerGraphToolStripMenuItem.Checked = false; }
void item_MouseEnter(object sender, EventArgs e) { ToolStripMenuItem m = sender as ToolStripMenuItem; m.ShowDropDown(); }
/// <summary> /// Return a menu item /// </summary> /// <param name="addDynamics">bool is dynamic entries need to be added</param> /// <param name="menu">ContextMenuStrip</param> /// <param name="destinationClickHandler">EventHandler</param> /// <param name="bitmapScaleHandler">BitmapScaleHandler</param> /// <returns>ToolStripMenuItem</returns> public virtual ToolStripMenuItem GetMenuItem(bool addDynamics, ContextMenuStrip menu, EventHandler destinationClickHandler, BitmapScaleHandler <IDestination> bitmapScaleHandler) { var basisMenuItem = new ToolStripMenuItem(Description) { Tag = this, Text = Description }; bitmapScaleHandler.AddTarget(basisMenuItem, this); AddTagEvents(basisMenuItem, menu, Description); basisMenuItem.Click -= destinationClickHandler; basisMenuItem.Click += destinationClickHandler; if (IsDynamic && addDynamics) { basisMenuItem.DropDownOpening += async(sender, args) => { if (basisMenuItem.DropDownItems.Count != 0) { return; } // Give the destination a chance to prepare for the destinations await PrepareDynamicDestinations(basisMenuItem).ConfigureAwait(true); var subDestinations = new List <IDestination>(); // Fixing Bug #3536968 by catching the COMException (every exception) and not displaying the "subDestinations" try { subDestinations.AddRange(DynamicDestinations()); } catch (Exception ex) { Log.Error().WriteLine("Skipping {0}, due to the following error: {1}", Description, ex.Message); } await AfterDynamicDestinations(basisMenuItem).ConfigureAwait(true); if (subDestinations.Count <= 0) { return; } if (UseDynamicsOnly && subDestinations.Count == 1) { basisMenuItem.Tag = subDestinations[0]; basisMenuItem.Text = subDestinations[0].Description; basisMenuItem.Click -= destinationClickHandler; basisMenuItem.Click += destinationClickHandler; } else { foreach (var subDestination in subDestinations) { var destinationMenuItem = new ToolStripMenuItem(subDestination.Description) { Tag = subDestination, }; bitmapScaleHandler.AddTarget(destinationMenuItem, subDestination); destinationMenuItem.Click += destinationClickHandler; AddTagEvents(destinationMenuItem, menu, subDestination.Description); basisMenuItem.DropDownItems.Add(destinationMenuItem); } basisMenuItem.ShowDropDown(); } }; } return(basisMenuItem); }