當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。