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


C# Menu.Remove方法代码示例

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


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

示例1: BuildMenu

		/// <summary>
		/// Builds the menu.
		/// </summary>
		private void BuildMenu ()
		{
			MenuBar mbar = (this.UIManager.GetWidget ("/menubarMain") as MenuBar);

			#region FileMenu
			Menu filemenu = new Menu ();
			MenuItem file = new MenuItem ("File");
			file.Submenu = filemenu;
			MenuItem newoption = new MenuItem ("New");
			MenuItem openoption = openAction.CreateMenuItem () as MenuItem;
			MenuItem saveoption = saveAction.CreateMenuItem () as MenuItem; 
			MenuItem saveasoption = saveAsAction.CreateMenuItem () as MenuItem;
			MenuItem recentconfigs = new ImageMenuItem ("Recent Configurations");
			MenuItem exit = quitAction.CreateMenuItem () as MenuItem;

			Menu LastConfigurations = new Menu ();
			recentconfigs.Activated += (object sender, EventArgs e) =>
			{
				foreach (MenuItem mi in LastConfigurations.AllChildren)
				{
					LastConfigurations.Remove (mi);
				}

				foreach (string s in con.LastConfigurationLocations)
				{
					if (!string.IsNullOrEmpty (s))
					{
						MenuItem entry = new MenuItem (s);
						entry.ButtonPressEvent += (object o, ButtonPressEventArgs args) => RunOpenConfig (s);
						LastConfigurations.Append (entry);
					}
				}
				LastConfigurations.ShowAll ();
			};
			exit.Activated += (sender, e) => OnDeleteEvent (null, null);

			filemenu.Append (newoption);
			filemenu.Append (openoption);
			filemenu.Append (saveoption);
			filemenu.Append (saveasoption);
			filemenu.Append (new SeparatorMenuItem ());
			filemenu.Append (recentconfigs);
			recentconfigs.Submenu = LastConfigurations;
			filemenu.Append (new SeparatorMenuItem ());
			filemenu.Append (exit);
			mbar.Append (file);
			#endregion

			#region Edit
			Menu editmenu = new Menu ();
			MenuItem edit = new MenuItem ("Edit");
			edit.Submenu = editmenu;
			MenuItem preferences = preferencesAction.CreateMenuItem () as MenuItem;
			editmenu.Append (preferences);

			mbar.Append (edit);
			#endregion

			#region ConnectionMenu
			Menu connectionmenu = new Menu ();
			MenuItem connection = new MenuItem ("Connection");
			connection.Submenu = connectionmenu;
			var autoConnect = refreshAction.CreateMenuItem () as MenuItem;
			Menu portmenu = new Menu ();
			MenuItem port = new MenuItem ("Port");
			connectionmenu.Append (autoConnect);
			connectionmenu.Append (port);
			port.Submenu = portmenu;

			port.Activated += (object sender, EventArgs e) =>
			{
				foreach (MenuItem mi in portmenu.AllChildren)
				{
					portmenu.Remove (mi);
				}
				foreach (String s in System.IO.Ports.SerialPort.GetPortNames())
				{
					CheckMenuItem portname = new CheckMenuItem (s);
					if (ArduinoController.SerialPortName != null)
					{
						if (ArduinoController.SerialPortName.Equals (s) && ArduinoController.IsConnected)
						{
							portname.Toggle ();
						}
					}

					portname.Toggled += (object senderer, EventArgs ee) =>
					{
						if ((senderer as CheckMenuItem).Active)
						{
							ArduinoController.SerialPortName = ((senderer as CheckMenuItem).Child as Label).Text;
							ArduinoController.Setup ();
						} else
						{
							ArduinoController.Disconnect ();
						}
					};
//.........这里部分代码省略.........
开发者ID:Onkeliroh,项目名称:DSA,代码行数:101,代码来源:MainWindow.cs


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