当前位置: 首页>>代码示例>>C#>>正文


C# ContextMenuStrip.Close方法代码示例

本文整理汇总了C#中System.Windows.Forms.ContextMenuStrip.Close方法的典型用法代码示例。如果您正苦于以下问题:C# ContextMenuStrip.Close方法的具体用法?C# ContextMenuStrip.Close怎么用?C# ContextMenuStrip.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.ContextMenuStrip的用法示例。


在下文中一共展示了ContextMenuStrip.Close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShowMenu

        public void ShowMenu()
        {
            ContextMenuStrip cms = new ContextMenuStrip
            {
                Font = new Font("Arial", 10f),
                AutoClose = false,
                ShowImageMargin = false
            };

            if (Program.Settings != null && Program.Settings.QuickTaskPresets != null && Program.Settings.QuickTaskPresets.Count > 0)
            {
                foreach (QuickTaskInfo taskInfo in Program.Settings.QuickTaskPresets)
                {
                    if (taskInfo.IsValid)
                    {
                        ToolStripMenuItem tsmi = new ToolStripMenuItem { Text = taskInfo.ToString().Replace("&", "&&"), Tag = taskInfo };
                        tsmi.Click += (sender, e) =>
                        {
                            QuickTaskInfo selectedTaskInfo = ((ToolStripMenuItem)sender).Tag as QuickTaskInfo;
                            cms.Close();
                            OnTaskInfoSelected(selectedTaskInfo);
                        };
                        cms.Items.Add(tsmi);
                    }
                    else
                    {
                        cms.Items.Add(new ToolStripSeparator());
                    }
                }

                cms.Items[0].Select();

                cms.Items.Add(new ToolStripSeparator());
            }

            // Translate
            ToolStripMenuItem tsmiEdit = new ToolStripMenuItem("Edit this menu...");
            tsmiEdit.Click += (sender, e) =>
            {
                cms.Close();
                new QuickTaskMenuEditorForm().ShowDialog();
            };
            cms.Items.Add(tsmiEdit);

            cms.Items.Add(new ToolStripSeparator());

            ToolStripMenuItem tsmiCancel = new ToolStripMenuItem("Cancel");
            tsmiCancel.Click += (sender, e) => cms.Close();
            cms.Items.Add(tsmiCancel);

            Point cursorPosition = CaptureHelpers.GetCursorPosition();
            cursorPosition.Offset(-10, -10);
            cms.Show(cursorPosition);
        }
开发者ID:TJHeuvel,项目名称:ShareX,代码行数:54,代码来源:QuickTaskMenu.cs

示例2: ShowMenu

        public void ShowMenu()
        {
            ContextMenuStrip cms = new ContextMenuStrip()
            {
                Font = new Font("Arial", 10f),
                AutoClose = false
            };

            ToolStripMenuItem tsmiContinue = new ToolStripMenuItem(Resources.QuickTaskMenu_ShowMenu_Continue);
            tsmiContinue.Image = Resources.control;
            tsmiContinue.Click += (sender, e) =>
            {
                cms.Close();
                OnTaskInfoSelected(null);
            };
            cms.Items.Add(tsmiContinue);

            cms.Items.Add(new ToolStripSeparator());

            if (Program.Settings != null && Program.Settings.QuickTaskPresets != null && Program.Settings.QuickTaskPresets.Count > 0)
            {
                foreach (QuickTaskInfo taskInfo in Program.Settings.QuickTaskPresets)
                {
                    if (taskInfo.IsValid)
                    {
                        ToolStripMenuItem tsmi = new ToolStripMenuItem { Text = taskInfo.ToString().Replace("&", "&&"), Tag = taskInfo };
                        tsmi.Image = FindSuitableIcon(taskInfo);
                        tsmi.Click += (sender, e) =>
                        {
                            QuickTaskInfo selectedTaskInfo = ((ToolStripMenuItem)sender).Tag as QuickTaskInfo;
                            cms.Close();
                            OnTaskInfoSelected(selectedTaskInfo);
                        };
                        cms.Items.Add(tsmi);
                    }
                    else
                    {
                        cms.Items.Add(new ToolStripSeparator());
                    }
                }

                cms.Items[0].Select();

                cms.Items.Add(new ToolStripSeparator());
            }

            ToolStripMenuItem tsmiEdit = new ToolStripMenuItem(Resources.QuickTaskMenu_ShowMenu_Edit_this_menu___);
            tsmiEdit.Image = Resources.pencil;
            tsmiEdit.Click += (sender, e) =>
            {
                cms.Close();
                new QuickTaskMenuEditorForm().ShowDialog();
            };
            cms.Items.Add(tsmiEdit);

            cms.Items.Add(new ToolStripSeparator());

            ToolStripMenuItem tsmiCancel = new ToolStripMenuItem(Resources.QuickTaskMenu_ShowMenu_Cancel);
            tsmiCancel.Image = Resources.cross;
            tsmiCancel.Click += (sender, e) => cms.Close();
            cms.Items.Add(tsmiCancel);

            Point cursorPosition = CaptureHelpers.GetCursorPosition();
            cursorPosition.Offset(-10, -10);
            cms.Show(cursorPosition);
        }
开发者ID:ElectronicWar,项目名称:ShareX,代码行数:66,代码来源:QuickTaskMenu.cs

示例3: CreateCodesMenu

        public static ContextMenuStrip CreateCodesMenu(TextBox tb, params ReplacementVariables[] ignoreList)
        {
            ContextMenuStrip cms = new ContextMenuStrip
            {
                Font = new XmlFont("Lucida Console", 8),
                AutoClose = false,
                Opacity = 0.9,
                ShowImageMargin = false
            };

            var variables = Enum.GetValues(typeof(ReplacementVariables)).Cast<ReplacementVariables>().Where(x => !ignoreList.Contains(x)).
                Select(x => new
                {
                    Name = ReplacementExtension.Prefix + Enum.GetName(typeof(ReplacementVariables), x),
                    Description = x.GetDescription(),
                    Enum = x
                });

            foreach (var variable in variables)
            {
                ToolStripMenuItem tsmi = new ToolStripMenuItem { Text = string.Format("{0} - {1}", variable.Name, variable.Description), Tag = variable.Name };
                tsmi.Click += (sender, e) =>
                {
                    string text = ((ToolStripMenuItem)sender).Tag.ToString();
                    tb.AppendTextToSelection(text);
                };
                cms.Items.Add(tsmi);
            }

            cms.Items.Add(new ToolStripSeparator());

            ToolStripMenuItem tsmiClose = new ToolStripMenuItem("Close");
            tsmiClose.Click += (sender, e) => cms.Close();
            cms.Items.Add(tsmiClose);

            tb.MouseDown += (sender, e) =>
            {
                if (cms.Items.Count > 0) cms.Show(tb, new Point(tb.Width + 1, 0));
            };

            tb.Leave += (sender, e) =>
            {
                if (cms.Visible) cms.Close();
            };

            tb.KeyDown += (sender, e) =>
            {
                if ((e.KeyCode == Keys.Enter || e.KeyCode == Keys.Escape) && cms.Visible)
                {
                    cms.Close();
                    e.SuppressKeyPress = true;
                }
            };

            tb.Disposed += (sender, e) => cms.Dispose();

            return cms;
        }
开发者ID:jesse-gao,项目名称:ShareX,代码行数:58,代码来源:NameParser.cs

示例4: CreateMenu

        ContextMenuStrip CreateMenu(XGEffectBlockType type)
        {
            ContextMenuStrip strip = new ContextMenuStrip();
            EffectSelectorMenu container = new EffectSelectorMenu();
            strip.Items.Add(container);

            for (int i = 0; i < XGEffect.AllEffects.Count; i++)
            {
                XGEffect efct = XGEffect.AllEffects[i];
                if (type >= XGEffectBlockType.Variation
                    || (type == XGEffectBlockType.Reverb && efct.SelectableForReverb)
                    || (type == XGEffectBlockType.Chorus && efct.SelectableForChorus))
                {
                    container.AddButton(XGEffect.AllEffects[i].Name,
                        XGEffect.AllEffects[i].Description,
                        () => { strip.Close(); DecideEffect(type, efct); },
                        efct.SelectableForReverb & efct.SelectableForChorus ? Color.DarkGray :
                        efct.SelectableForReverb ? Color.Maroon :
                        efct.SelectableForChorus ? Color.Teal :
                        Color.Navy
                        );
                }
            }
            strip.LayoutStyle = ToolStripLayoutStyle.Flow;

            return strip;
        }
开发者ID:ttsuki,项目名称:XGMidiControllerForMU2000EX,代码行数:27,代码来源:EffectParameterGrid.cs

示例5: ShowPickerMenu

		/// <summary>
		/// This method will create and show the destination picker menu
		/// </summary>
		/// <param name="addDynamics">Boolean if the dynamic values also need to be added</param>
		/// <param name="surface">The surface which can be exported</param>
		/// <param name="captureDetails">Details for the surface</param>
		/// <param name="destinations">The list of destinations to show</param>
		/// <returns></returns>
		public ExportInformation ShowPickerMenu(bool addDynamics, ISurface surface, ICaptureDetails captureDetails, IEnumerable<IDestination> destinations) {
			// Generate an empty ExportInformation object, for when nothing was selected.
			ExportInformation exportInformation = new ExportInformation(Designation, Language.GetString("settings_destination_picker"));
			ContextMenuStrip menu = new ContextMenuStrip();
			menu.ImageScalingSize = configuration.IconSize;
			menu.Tag = null;

			menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) {
				LOG.DebugFormat("Close reason: {0}", eventArgs.CloseReason);
				switch (eventArgs.CloseReason) {
					case ToolStripDropDownCloseReason.AppFocusChange:
						if (menu.Tag == null) {
							// Do not allow the close if the tag is not set, this means the user clicked somewhere else.
							eventArgs.Cancel = true;
						} else {
							LOG.DebugFormat("Letting the menu 'close' as the tag is set to '{0}'", menu.Tag);
						}
						break;
					case ToolStripDropDownCloseReason.ItemClicked:
					case ToolStripDropDownCloseReason.CloseCalled:
						// The ContextMenuStrip can be "closed" for these reasons.
						break;
					case ToolStripDropDownCloseReason.Keyboard:
						// Dispose as the close is clicked
						if (!captureDetails.HasDestination("Editor")) {
							surface.Dispose();
							surface = null;
						}
						break;
					default:
						eventArgs.Cancel = true;
						break;
				}
			};
			menu.MouseEnter += delegate(object source, EventArgs eventArgs) {
				// in case the menu has been unfocused, focus again so that dropdown menus will still open on mouseenter
				if(!menu.ContainsFocus) menu.Focus();
			};
			foreach (IDestination destination in destinations) {
				// Fix foreach loop variable for the delegate
				ToolStripMenuItem item = destination.GetMenuItem(addDynamics, menu,
					delegate(object sender, EventArgs e) {
						ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem;
						if (toolStripMenuItem == null) {
							return;
						}
						IDestination clickedDestination = (IDestination)toolStripMenuItem.Tag;
						if (clickedDestination == null) {
							return;
						}
						menu.Tag = clickedDestination.Designation;
						// Export
						exportInformation = clickedDestination.ExportCapture(true, surface, captureDetails);
						if (exportInformation != null && exportInformation.ExportMade) {
							LOG.InfoFormat("Export to {0} success, closing menu", exportInformation.DestinationDescription);
							// close menu if the destination wasn't the editor
							menu.Close();

							// Cleanup surface, only if there is no editor in the destinations and we didn't export to the editor
							if (!captureDetails.HasDestination("Editor") && !"Editor".Equals(clickedDestination.Designation)) {
								surface.Dispose();
								surface = null;
							}
						} else {
							LOG.Info("Export cancelled or failed, showing menu again");

							// Make sure a click besides the menu don't close it.
							menu.Tag = null;

							// This prevents the problem that the context menu shows in the task-bar
							ShowMenuAtCursor(menu);
						}
					}
				);
				if (item != null) {
					menu.Items.Add(item);
				}
			}
			// Close
			menu.Items.Add(new ToolStripSeparator());
			ToolStripMenuItem closeItem = new ToolStripMenuItem(Language.GetString("editor_close"));
			closeItem.Image = GreenshotResources.getImage("Close.Image");
			closeItem.Click += delegate {
				// This menu entry is the close itself, we can dispose the surface
				menu.Close();
				if (!captureDetails.HasDestination("Editor")) {
					surface.Dispose();
					surface = null;
				}
			};
			menu.Items.Add(closeItem);

//.........这里部分代码省略.........
开发者ID:logtcn,项目名称:greenshot,代码行数:101,代码来源:AbstractDestination.cs

示例6: ShowHideTest

		public void ShowHideTest ()
		{
			ContextMenuStrip formMenu = new ContextMenuStrip ();
			formMenu.Items.Add ("form item 1");
			Form.ContextMenuStrip = formMenu;

			Label label = new Label ();
			label.Text = "I have my own context menu";
			ContextMenuStrip labelMenu = new ContextMenuStrip ();
			labelMenu.Items.Add ("label item 1");
			label.ContextMenuStrip = labelMenu;
			Form.Controls.Add (label);
			label.Show ();

			var labelProvider = ProviderFactory.FindProvider (label);
			Assert.IsNotNull (labelProvider,
			                  "Form's label should have a provider");

			// No menu providers unless shown
			IRawElementProviderFragment formMenuProvider =
				ProviderFactory.FindProvider (formMenu);
			Assert.IsNull (formMenuProvider,
			               "Form menu provider not expected until shown");
			IRawElementProviderFragment labelMenuProvider =
				ProviderFactory.FindProvider (labelMenu);
			Assert.IsNull (labelMenuProvider,
			               "Label menu provider not expected until shown");

			bridge.ResetEventLists ();

			// Test showing Form menu
			formMenu.Show ();

			formMenuProvider =
				ProviderFactory.FindProvider (formMenu);
			Assert.IsNotNull (formMenuProvider,
			                  "Form menu provider expected once menu is shown");
			labelMenuProvider =
				ProviderFactory.FindProvider (labelMenu);
			Assert.IsNull (labelMenuProvider,
			               "Label menu provider not expected until shown");

			Assert.AreEqual (FormProvider,
			                 formMenuProvider.Navigate (NavigateDirection.Parent),
			                 "Form menu parent should be Form");
			Assert.IsTrue (ProviderContainsChild (FormProvider, formMenuProvider),
			               "Form menu should be Form's child");

			var tuple = bridge.GetAutomationEventFrom (formMenuProvider,
			                                           AEIds.MenuOpenedEvent.Id);
			Assert.IsNotNull (tuple,
			                  "MenuOpenedEvent expected");

			bridge.ResetEventLists ();

			// Test closing Form menu
			formMenu.Close ();

			tuple = bridge.GetAutomationEventFrom (formMenuProvider,
			                                       AEIds.MenuClosedEvent.Id);
			Assert.IsNotNull (tuple,
			                  "MenuClosedEvent expected");

			formMenuProvider =
				ProviderFactory.FindProvider (formMenu);
			Assert.IsNull (formMenuProvider,
			               "Form menu provider should be gone after menu closed");
			Assert.IsFalse (ProviderContainsChildOfType (FormProvider, ControlType.Menu),
			                "Form should have no menu child after menu closed");

			bridge.ResetEventLists ();

			// Test showing Label menu
			labelMenu.Show ();

			formMenuProvider =
				ProviderFactory.FindProvider (formMenu);
			Assert.IsNull (formMenuProvider,
			                  "Form menu provider not expected while closed");
			labelMenuProvider =
				ProviderFactory.FindProvider (labelMenu);
			Assert.IsNotNull (labelMenuProvider,
			               "Label menu provider expected once menu is shown");

			Assert.AreEqual (labelProvider,
			                 labelMenuProvider.Navigate (NavigateDirection.Parent),
			                 "Label menu parent should be Label");
			Assert.IsTrue (ProviderContainsChild (labelProvider, labelMenuProvider),
			               "Label menu should be Label's child");

			tuple = bridge.GetAutomationEventFrom (labelMenuProvider,
			                                           AEIds.MenuOpenedEvent.Id);
			Assert.IsNotNull (tuple,
			                  "MenuOpenedEvent expected");

			bridge.ResetEventLists ();

			// Test closing Label menu
			labelMenu.Close ();

//.........这里部分代码省略.........
开发者ID:mono,项目名称:uia2atk,代码行数:101,代码来源:ContextMenuStripProviderTest.cs

示例7: CreateContextMenu

        private void CreateContextMenu()
        {
            cmsContextMenu = new ContextMenuStrip(form.components);
            cmsContextMenu.Renderer = new ToolStripCheckedBoldRenderer();
            cmsContextMenu.IgnoreSeparatorClick();

            cmsContextMenu.PreviewKeyDown += (sender, e) =>
            {
                if (e.KeyCode == Keys.Escape)
                {
                    e.IsInputKey = true;
                }
            };

            cmsContextMenu.KeyUp += (sender, e) =>
            {
                if (e.KeyCode == Keys.Escape)
                {
                    cmsContextMenu.Close();
                }
            };

            #region Main

            ToolStripMenuItem tsmiCancelCapture = new ToolStripMenuItem("Cancel capture");
            tsmiCancelCapture.Image = Resources.prohibition;
            tsmiCancelCapture.Click += (sender, e) => form.Close(RegionResult.Close);
            cmsContextMenu.Items.Add(tsmiCancelCapture);

            ToolStripMenuItem tsmiCloseMenu = new ToolStripMenuItem("Close menu");
            tsmiCloseMenu.Image = Resources.cross;
            tsmiCloseMenu.Click += (sender, e) => cmsContextMenu.Close();
            cmsContextMenu.Items.Add(tsmiCloseMenu);

            #endregion Main

            #region Selected object

            tssObjectOptions = new ToolStripSeparator();
            cmsContextMenu.Items.Add(tssObjectOptions);

            tsmiDeleteSelected = new ToolStripMenuItem("Delete selected object");
            tsmiDeleteSelected.Image = Resources.layer__minus;
            tsmiDeleteSelected.Click += (sender, e) => DeleteCurrentShape();
            cmsContextMenu.Items.Add(tsmiDeleteSelected);

            tsmiDeleteAll = new ToolStripMenuItem("Delete all objects");
            tsmiDeleteAll.Image = Resources.minus;
            tsmiDeleteAll.Click += (sender, e) => ClearAll();
            cmsContextMenu.Items.Add(tsmiDeleteAll);

            #endregion Selected object

            #region Tools

            cmsContextMenu.Items.Add(new ToolStripSeparator());

            foreach (ShapeType shapeType in Helpers.GetEnums<ShapeType>())
            {
                ToolStripMenuItem tsmiShapeType = new ToolStripMenuItem(shapeType.GetLocalizedDescription());

                Image img = null;

                switch (shapeType)
                {
                    case ShapeType.RegionRectangle:
                        img = Resources.layer_shape_region;
                        break;
                    case ShapeType.RegionRoundedRectangle:
                        img = Resources.layer_shape_round_region;
                        break;
                    case ShapeType.RegionEllipse:
                        img = Resources.layer_shape_ellipse_region;
                        break;
                    case ShapeType.DrawingRectangle:
                        img = Resources.layer_shape;
                        break;
                    case ShapeType.DrawingRoundedRectangle:
                        img = Resources.layer_shape_round;
                        break;
                    case ShapeType.DrawingEllipse:
                        img = Resources.layer_shape_ellipse;
                        break;
                    case ShapeType.DrawingLine:
                        img = Resources.layer_shape_line;
                        break;
                    case ShapeType.DrawingArrow:
                        img = Resources.layer_shape_arrow;
                        break;
                    case ShapeType.DrawingText:
                        img = Resources.layer_shape_text;
                        break;
                    case ShapeType.DrawingStep:
                        img = Resources.counter_reset;
                        break;
                    case ShapeType.DrawingBlur:
                        img = Resources.layer_shade;
                        break;
                    case ShapeType.DrawingPixelate:
                        img = Resources.grid;
//.........这里部分代码省略.........
开发者ID:Xanaxiel,项目名称:ShareX,代码行数:101,代码来源:ShapeManager.cs

示例8: TemplateButon_Click

        private void TemplateButon_Click(object sender, EventArgs e) {
            string addItemStr = Properties.Resources.SAVE_CURRENT_PREAMBLE + "...";
            string manageItemStr = Properties.Resources.MANAGE_TEMPLATES + "...";
            var menu = new ContextMenuStrip();
            foreach(var d in Properties.Settings.Default.preambleTemplates) {
                menu.Items.Add(new ToolStripMenuItem(d.Key) { Tag = d.Key });
            }
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem(addItemStr) { Tag = addItemStr });
            menu.Items.Add(new ToolStripMenuItem(manageItemStr) { Tag = manageItemStr });
            menu.ItemClicked += ((ss, ee) => {
                menu.Close();
                var tag = (string) ee.ClickedItem.Tag;
                if(tag == manageItemStr) {
                    var managedlg = new ManageTemplateDialog(Properties.Settings.Default.preambleTemplates, preambleTextBox.Text, new List<string> { manageItemStr, addItemStr ,""});
                    if(managedlg.ShowDialog(mainForm) == System.Windows.Forms.DialogResult.OK) {
                        Properties.Settings.Default.preambleTemplates = managedlg.Templates;
                    }
                }else if(tag == addItemStr){
                    var input = new InputComboDialog(
                        Properties.Resources.ADD_TEMPLATEMSG,Properties.Resources.INPUTE_TEMPLATE_NAME,
                        Properties.Settings.Default.preambleTemplates.Select(d => d.Key).ToList());
                    input.OKButtonClicked += ((sss, eee) => {
                        if(eee.InputedText == manageItemStr || eee.InputedText == addItemStr || eee.InputedText == "") {
                            MessageBox.Show(String.Format(Properties.Resources.INPUTE_TEMPLATE_NAME, eee.InputedText), "TeX2img");
                            eee.Cancel = true;
                        } else if(Properties.Settings.Default.preambleTemplates.ContainsKey(eee.InputedText)) {
                            if(MessageBox.Show(
                                String.Format(Properties.Resources.OVERWRITETEMPLATEMSG,eee.InputedText), "TeX2img", MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes) {
                                eee.Cancel = true;
                            }
                        }
                    });
                    if(input.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
                        Properties.Settings.Default.preambleTemplates[input.InputedText] = preambleTextBox.Text;
                    }
                } else {
                    try {
                        var text = Properties.Settings.Default.preambleTemplates[tag];
                        if(text != null) {
                            if(MessageBox.Show(String.Format(Properties.Resources.CHANGE_CURRENTPREAMBLE, text), "TeX2img", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) {
                                preambleTextBox.Text = ChangeReturnCode(text);

                                var latex = Properties.Settings.Default.GuessPlatexPath(text, "");
                                var dvipdfmx = Properties.Settings.Default.GuessDvipdfmxPath(text, "");
                                string str = "";
                                if(latex != "") str += "\nlatex: " + latex;
                                if(dvipdfmx != "") str += "\nDVI driver: " + dvipdfmx;
                                if(str != "") {
                                    if(MessageBox.Show(String.Format(Properties.Resources.DETECT_RECOMMENDED_PATH, str), "TeX2img", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) {
                                        if(latex != "") Properties.Settings.Default.platexPath = latex;
                                        if(dvipdfmx != "") Properties.Settings.Default.dvipdfmxPath = dvipdfmx;
                                    }
                                }
                            }
                        }
                    }
                    catch(KeyNotFoundException) { }
                    catch(ArgumentNullException) { }
                }
            });

            var btn = (Button) sender;
            menu.Show(btn, new Point(0, btn.Height));
        }
开发者ID:abenori,项目名称:TeX2img,代码行数:65,代码来源:PreambleForm.cs

示例9: CreatePickerMenu

        public static ContextMenuStrip CreatePickerMenu(bool addDynamics, ISurface surface, ICaptureDetails captureDetails, IEnumerable<IDestination> destinations)
        {
            ContextMenuStrip menu = new ContextMenuStrip();
            menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) {
                LOG.DebugFormat("Close reason: {0}", eventArgs.CloseReason);
                if (eventArgs.CloseReason != ToolStripDropDownCloseReason.ItemClicked && eventArgs.CloseReason != ToolStripDropDownCloseReason.CloseCalled) {
                    eventArgs.Cancel = true;
                }
            };
            foreach (IDestination destination in destinations) {
                // Fix foreach loop variable for the delegate
                ToolStripMenuItem item = destination.GetMenuItem(addDynamics,
                    delegate(object sender, EventArgs e) {
                        ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem;
                        if (toolStripMenuItem == null) {
                            return;
                        }
                        IDestination clickedDestination = (IDestination)toolStripMenuItem.Tag;
                        if (clickedDestination == null) {
                            return;
                        }
                        // Make sure the menu is closed
                        menu.Close();
                        bool result = clickedDestination.ExportCapture(true, surface, captureDetails);
                        // TODO: Find some better way to detect that we exported to the editor
                        if (!EditorDestination.DESIGNATION.Equals(clickedDestination.Designation) || result == false) {
                            LOG.DebugFormat("Disposing as Destination was {0} and result {1}", clickedDestination.Description, result);
                            // Cleanup surface
                            surface.Dispose();
                        }
                    }
                );
                if (item != null) {
                    menu.Items.Add(item);
                }
            }
            // Close
            menu.Items.Add(new ToolStripSeparator());
            ToolStripMenuItem closeItem = new ToolStripMenuItem(Language.GetString(LangKey.editor_close));
            closeItem.Image = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(ImageEditorForm)).GetObject("closeToolStripMenuItem.Image")));
            closeItem.Click += delegate {
                // This menu entry is the close itself, we can dispose the surface
                menu.Close();
                // Dispose as the close is clicked
                surface.Dispose();
            };
            menu.Items.Add(closeItem);

            return menu;
        }
开发者ID:modulexcite,项目名称:ZScreen_Google_Code,代码行数:50,代码来源:PickerDestination.cs


注:本文中的System.Windows.Forms.ContextMenuStrip.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。