我正在为一个项目开发系统托盘应用程序。当我单击“切换开启”时,我目前卡住了它不会自行更改为“切换关闭”,我希望也许有人能告诉我我做错了什么并帮助我修复它。
上下文菜单的代码
using System;
using System.Diagnostics;
using System.Windows.Forms;
using TestApplicationforRIVC.Properties;
using System.Drawing;
namespace TestApplicationforRIVC {
class RIVCContextMenu {
//Is Add Box Displayed?
bool isAddLoaded = false;
//Is the Clear box Displayed?
bool isClearLoaded = false;
//Is it listening for voice?
bool toggleOn = false;
//Creates this Instance
public ContextMenuStrip Create() {
//Add the Default Menu Options
ContextMenuStrip menu = new ContextMenuStrip();
ToolStripMenuItem item;
ToolStripMenuItem off;
ToolStripSeparator sep;
if(toggleOn) {
//Toggle Off
item = new ToolStripMenuItem();
item.Text = "Toggle Off";
item.Click += new EventHandler(toggleOffClick);
item.Image = Resources.toggleOff;
menu.Items.Add(item);
}
if(!toggleOn) {
//Toggle On
item = new ToolStripMenuItem();
item.Text = "Toggle On";
item.Click += new EventHandler(toggleOnClick);
item.Image = Resources.toggleOn;
menu.Items.Add(item);
}
// Separator.
sep = new ToolStripSeparator();
menu.Items.Add(sep);
//Add to RIVC Library
item = new ToolStripMenuItem();
item.Text = "Add to Library";
item.Click += new EventHandler(addClick);
item.Image = Resources.Add;
menu.Items.Add(item);
//Clear RIVC Library
item = new ToolStripMenuItem();
item.Text = "Clear Library";
item.Click += new EventHandler(clearClick);
item.Image = Resources.Delete;
menu.Items.Add(item);
// Separator.
sep = new ToolStripSeparator();
menu.Items.Add(sep);
//Exit Program
item = new ToolStripMenuItem();
item.Text = "Exit";
item.Click += new System.EventHandler(exitClick);
item.Image = Resources.Exit;
menu.Items.Add(item);
return menu;
}
//Handles the Click Event of the Toggle On Control
void toggleOnClick(object sender, EventArgs e) {
toggleOn = true;
}
//Handles the Click Even of the Toggle Off Control
void toggleOffClick(object sender, EventArgs e) {
toggleOn = false;
}
//Handles the Click Event of the Add Control
void addClick(object sender, EventArgs e) {
if(!isAddLoaded) {
isAddLoaded = true;
//enter Dialog Box Info
isAddLoaded = false;
}
}
//Handles the Click Event of the Clear Control
void clearClick(object sender, EventArgs e) {
if(!isClearLoaded) {
isClearLoaded = true;
//enter dialog box info
isClearLoaded = false;
}
}
//Handles the Click Event of the Exit Control
void exitClick(object sender, EventArgs e) {
Application.Exit();
}
}
}
希望你们能帮助我解决这个小错误。