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


C# MenuItem.PerformClick方法代码示例

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


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

示例1: Caffeine

        public Caffeine()
        {
            trayIcon = new NotifyIcon();

            MenuItem[] menu = new[]
            {
                toggleMenuItem =
                    new MenuItem("Enable Caffeine", new EventHandler(ToggleClicked), Shortcut.None),
                new MenuItem("-"),
                new MenuItem("Quit", new EventHandler(Quit), Shortcut.None),
            };
            trayMenu = new ContextMenu(menu);

            toggleMenuItem.DefaultItem = true;

            trayIcon.ContextMenu = trayMenu;
            trayIcon.DoubleClick += (o, args) => toggleMenuItem.PerformClick();
            trayIcon.Text = "Caffeine";

            Enabled = false;

            Application.ApplicationExit += (o, args) =>
            {
                // Hide the tray icon
                trayIcon.Visible = false;

                // This will quit the wake thread upon the next iteration of its loop.
                Running = false;

                // Interrupt the thread if it's sleeping so that it will quit.
                if (wakeThread.ThreadState == ThreadState.WaitSleepJoin)
                    wakeThread.Interrupt();
            };

            Start();
        }
开发者ID:Forkk,项目名称:Caffeine,代码行数:36,代码来源:Caffeine.cs

示例2: InvokeMenuItemHelper

 // Called on worker thread to invoke a menu command.
 static void InvokeMenuItemHelper(MenuItem m, string args)
 {
     // Need to make cross-thread call to invoke. Don't block since the GUI thread won't pump messages.            
     m_mainForm.BeginInvoke(new MethodInvoker(delegate()
     {
         
         {
             m.PerformClick();
             WriteOutput("Done invoking menu command:" + args);
         }
         /*  */
     }));            
 }
开发者ID:Orvid,项目名称:Cosmos,代码行数:14,代码来源:gui.cs

示例3: IntializeContextMenu

        // Builds and returns a ContextMenu for the tray icon, including menu items for each power plan, one to allow the program to run at startup, and one to exit the program.
        ContextMenu IntializeContextMenu()
        {
            ContextMenu ret = new ContextMenu();

            // get power plans
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.FileName = "cmd";
            startInfo.Arguments = "/C powercfg -l";
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.RedirectStandardOutput = true;
            startInfo.UseShellExecute = false;
            process.StartInfo = startInfo;
            process.Start();

            System.IO.StreamReader output = process.StandardOutput;

            process.WaitForExit();

            // read first three lines of powercfg command to get to the list of power plans
            output.ReadLine();
            output.ReadLine();
            output.ReadLine();

            // read all power plans
            while (!output.EndOfStream)
            {
                String line = output.ReadLine();
                PowerMenuItem pmi = new PowerMenuItem();
                pmi.Guid = line.Split(' ')[3];
                pmi.PlanName = line.Substring(line.IndexOf('(') + 1, line.IndexOf(')') - line.IndexOf('(') - 1);
                pmi.Name = pmi.PlanName;
                pmi.Text = pmi.PlanName;
                pmi.Checked = line.EndsWith("*"); // * indicates that this is the active power plan
                pmi.Click += Pmi_Click;
                ret.MenuItems.Add(pmi);
            }

            // Menu item for running at startup.
            MenuItem runAtStartupItem = new MenuItem("Run At Startup");

            RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
            runAtStartupItem.Click += RunAtStartupItem_Click;
            //runAtStartupItem.Checked = IsStartupItem(rkApp); does not properly update the Checked property for some unkown reason
            runAtStartupItem.PerformClick(); // hacky way to accomplish properly updating the Checked property at startup
            runAtStartupItem.PerformClick();
            ret.MenuItems.Add(runAtStartupItem);

            ret.MenuItems.Add(new MenuItem("Exit", Exit)); // add Exit MenuItem

            return ret;
        }
开发者ID:andrewkolos,项目名称:PowerPlanToggler,代码行数:53,代码来源:Program.cs

示例4: Start

        private static void Start(string[] args)
        {
            Logger.Title = "DNSAgent - Starting ...";

            var version = Assembly.GetExecutingAssembly().GetName().Version;
            var buildTime = Utils.RetrieveLinkerTimestamp(Assembly.GetExecutingAssembly().Location);
            var programName = $"DNSAgent {version.Major}.{version.Minor}.{version.Build}";
            Logger.Info("{0} (build at {1})\n", programName, buildTime.ToString(CultureInfo.CurrentCulture));
            Logger.Info("Starting...");

            var options = ReadOptions();
            var rules = ReadRules();
            var listenEndpoints = options.ListenOn.Split(',');
            var startedEvent = new CountdownEvent(listenEndpoints.Length);
            lock (DnsAgents)
            {
                foreach (var listenOn in listenEndpoints)
                {
                    var agent = new DnsAgent(options, rules, listenOn.Trim(), AgentCommonCache);
                    agent.Started += () => startedEvent.Signal();
                    DnsAgents.Add(agent);
                }
            }
            if (Environment.UserInteractive)
            {
                lock (DnsAgents)
                {
                    if (DnsAgents.Any(agent => !agent.Start()))
                    {
                        PressAnyKeyToContinue();
                        return;
                    }
                }
                startedEvent.Wait();
                Logger.Title = "DNSAgent - Listening ...";
                Logger.Info("DNSAgent has been started.");
                Logger.Info("Press Ctrl-R to reload configurations, Ctrl-Q to stop and quit.");

                Task.Run(() =>
                {
                    var exit = false;
                    while (!exit)
                    {
                        var keyInfo = Console.ReadKey(true);
                        if (keyInfo.Modifiers != ConsoleModifiers.Control) continue;
                        switch (keyInfo.Key)
                        {
                            case ConsoleKey.R: // Reload options.cfg and rules.cfg
                                Reload();
                                break;

                            case ConsoleKey.Q:
                                exit = true;
                                Stop();
                                break;
                        }
                    }
                });

                var hideMenuItem = new MenuItem(options.HideOnStart ? "Show" : "Hide");
                if (options.HideOnStart)
                    ShowWindow(GetConsoleWindow(), SwHide);
                hideMenuItem.Click += (sender, eventArgs) =>
                {
                    if (hideMenuItem.Text == "Hide")
                    {
                        ShowWindow(GetConsoleWindow(), SwHide);
                        hideMenuItem.Text = "Show";
                    }
                    else
                    {
                        ShowWindow(GetConsoleWindow(), SwShow);
                        hideMenuItem.Text = "Hide";
                    }
                };
                _contextMenu = new ContextMenu(new[]
                {
                    hideMenuItem,
                    new MenuItem("Reload", (sender, eventArgs) => Reload()),
                    new MenuItem("Exit", (sender, eventArgs) => Stop(false))
                });
                _notifyIcon = new NotifyIcon
                {
                    Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location),
                    ContextMenu = _contextMenu,
                    Text = programName,
                    Visible = true
                };
                _notifyIcon.MouseClick += (sender, eventArgs) =>
                {
                    if (eventArgs.Button == MouseButtons.Left)
                        hideMenuItem.PerformClick();
                };
                Application.Run();
            }
            else
            {
                lock (DnsAgents)
                {
                    foreach (var agent in DnsAgents)
//.........这里部分代码省略.........
开发者ID:itplanes,项目名称:DNSAgent,代码行数:101,代码来源:Program.cs

示例5: ExecFocusedItem

		//	Used when the user executes the action of an item (press enter, shortcut)
		//	or a sub-popup menu has to be shown
		void ExecFocusedItem (Menu menu, MenuItem item)
		{
			if (item == null)
				return;

			if (!item.Enabled)
			 	return;
			 	
			if (item.IsPopup) {
				ShowSubPopup (menu, item);
			} else {
				Deactivate ();
				item.PerformClick ();
			}
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:17,代码来源:MenuAPI.cs

示例6: InitalNotifyIcon


//.........这里部分代码省略.........
                    rh = new RestHolidaySetting();

                    rh.UpdateWeather += () =>
                    {
                        LoadConfig();
                        Task.Factory.StartNew(UpdateWeather);
                    };

                    rh.ChangeCity += ChangeCity;

                    rh.StopWatchOpened += ShowStopWatchWindow;
                }

                rh.Show();
                rh.Activate();
            };

            notifyIconRestHolidayMenu.DefaultItem = true;

            var notifyIconStopWatchMenu = new System.Windows.Forms.MenuItem("秒表");

            notifyIconStopWatchMenu.Click += (sender, args) =>
            {
                ShowStopWatchWindow();
            };

            var notifyIconAboutMenu = new System.Windows.Forms.MenuItem("关于");
            notifyIconAboutMenu.Click += (sender, args) =>
            {
                if (aw == null)
                    aw = new AboutWindow();

                aw.Show();
                aw.Activate();
            };

            var notifyIconCloseMenu = new System.Windows.Forms.MenuItem("退出");
            notifyIconCloseMenu.Click += (sender, args) =>
            {
                notifyIcon.Visible = false;
                Environment.Exit(0);
            };

            var notifyIconMemoryClearMenu = new System.Windows.Forms.MenuItem("内存整理");
            notifyIconMemoryClearMenu.Click += async (sender, args) =>
            {
                notifyIconMemoryClearMenu.Enabled = false;
                await MemoryClear.ClearAsync();
                notifyIconMemoryClearMenu.Enabled = true;
            };

            var notifyIconWorkClearMenu = new System.Windows.Forms.MenuItem("上下班设置");
            notifyIconWorkClearMenu.Click += (sender, args) =>
            {
                var sww = new SetWorkTimeWindow();
                sww.ConfigChanged += () =>
                {
                    Config = ConfigHelper.Instance.Config;
                    UpdateWorkTimeSpan();
                };
                sww.ShowDialog();
            };

            var notifyIconMenu = new[]
            {
                notifyIconRestHolidayMenu,
                notifyIconStopWatchMenu,
                new System.Windows.Forms.MenuItem("-"),
                notifyIconMemoryClearMenu,
                new System.Windows.Forms.MenuItem("-"),
                notifyIconUpdateMenu,
                notifyIconChangeCityMenu,
                notifyIconWorkClearMenu,
                new System.Windows.Forms.MenuItem("-"),
                notifyIconTodayMenu,
                notifyIconLastMouthMenu,
                notifyIconNextMouthMenu,
                new System.Windows.Forms.MenuItem("-"),
                notifyIconAboutMenu,
                new System.Windows.Forms.MenuItem("-"),
                notifyIconCloseMenu
            };

            notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(notifyIconMenu);
            notifyIcon.MouseClick += (sender, args) =>
            {
                if (args.Button == MouseButtons.Right)
                    return;

                notifyIconRestHolidayMenu.PerformClick();
            };

            notifyIcon.DoubleClick += (sender, args) =>
            {
                LoadConfig();

                Task.Factory.StartNew(UpdateWeather);
                notifyIconRestHolidayMenu.PerformClick();
            };
        }
开发者ID:yjk282,项目名称:Weather,代码行数:101,代码来源:MainWindow.xaml.cs

示例7: InvokedEventTest

		public void InvokedEventTest ()
		{
			MenuItem menuItem = new MenuItem ();
			IRawElementProviderSimple provider = ProviderFactory.GetProvider (menuItem);
			
			bridge.ResetEventLists ();
			
			menuItem.PerformClick ();
			
			Assert.AreEqual (1,
			                 bridge.AutomationEvents.Count,
			                 "event count");
			
			AutomationEventTuple eventInfo =
				bridge.AutomationEvents [0];
			Assert.AreEqual (InvokePatternIdentifiers.InvokedEvent,
			                 eventInfo.eventId,
			                 "event type");
			Assert.AreEqual (provider,
			                 eventInfo.provider,
			                 "event element");
			Assert.AreEqual (InvokePatternIdentifiers.InvokedEvent,
			                 eventInfo.e.EventId,
			                 "event args event type");
		}
开发者ID:mono,项目名称:uia2atk,代码行数:25,代码来源:MenuItemProviderTest.cs

示例8: Start

        private static void Start(string[] args)
        {
            Logger.Title = "DNSAgent - Starting ...";

            var version = Assembly.GetExecutingAssembly().GetName().Version;
            var buildTime = Utils.RetrieveLinkerTimestamp(Assembly.GetExecutingAssembly().Location);
            var programName = string.Format("DNSAgent {0}.{1}.{2}", version.Major, version.Minor, version.Build);
            Logger.Info("{0} (build at {1})\n", programName, buildTime.ToString(CultureInfo.CurrentCulture));
            Logger.Info("Starting...");

            _dnsAgent = new DnsAgent(ReadOptions(), ReadRules());
            if (Environment.UserInteractive)
            {
                var startedWaitHandler = new ManualResetEvent(false);
                _dnsAgent.Started += () => { startedWaitHandler.Set(); };
                if (!_dnsAgent.Start())
                {
                    PressAnyKeyToContinue();
                    return;
                }
                startedWaitHandler.WaitOne();
                Logger.Info("Press Ctrl-R to reload configurations, Ctrl-Q to stop and quit.");

                Task.Run(() =>
                {
                    var exit = false;
                    while (!exit)
                    {
                        var keyInfo = Console.ReadKey(true);
                        if (keyInfo.Modifiers != ConsoleModifiers.Control) continue;
                        switch (keyInfo.Key)
                        {
                            case ConsoleKey.R: // Reload options.cfg and rules.cfg
                                Reload();
                                break;

                            case ConsoleKey.Q:
                                exit = true;
                                Stop();
                                break;
                        }
                    }
                });

                var hideOnStart = _dnsAgent.Options.HideOnStart;
                var hideMenuItem = new MenuItem(hideOnStart ? "Show" : "Hide");
                if (hideOnStart)
                    ShowWindow(GetConsoleWindow(), SwHide);
                hideMenuItem.Click += (sender, eventArgs) =>
                {
                    if (hideMenuItem.Text == "Hide")
                    {
                        ShowWindow(GetConsoleWindow(), SwHide);
                        hideMenuItem.Text = "Show";
                    }
                    else
                    {
                        ShowWindow(GetConsoleWindow(), SwShow);
                        hideMenuItem.Text = "Hide";
                    }
                };
                _contextMenu = new ContextMenu(new[]
                {
                    hideMenuItem,
                    new MenuItem("Reload", (sender, eventArgs) => Reload()),
                    new MenuItem("Exit", (sender, eventArgs) => Stop(false))
                });
                _notifyIcon = new NotifyIcon
                {
                    Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location),
                    ContextMenu = _contextMenu,
                    Text = programName,
                    Visible = true
                };
                _notifyIcon.MouseClick += (sender, eventArgs) =>
                {
                    if (eventArgs.Button == MouseButtons.Left)
                        hideMenuItem.PerformClick();
                };
                Application.Run();
            }
            else
                _dnsAgent.Start();
        }
开发者ID:MOODOO-SH,项目名称:DNSAgent,代码行数:84,代码来源:Program.cs


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