Compile error: X does not exist in the current context
The name 'MenuItems_Click' does not exist in the current context. Should I name it anywhere in ContextMenuStrip?
private void icnNotify_Click(object sender, EventArgs e)
{
// Create a new instance of the Favorites class
Favorite.Favorites objFavorites =
new Favorite.Favorites();
// Scan the Favorites folder
objFavorit开发者_开发百科es.ScanFavorites();
// Clear current menu items
FavoritesMenu.Items.Clear();
// Process each objWebFavorite object
// in the Favorites collection
foreach (Favorite.WebFavorite objWebFavorite
in objFavorites.FavoriteCollection)
{
// Declare a ToolStripMenuItem object
ToolStripMenuItem objMenuItem =
new ToolStripMenuItem();
// Set the properties of ToolStripMenuItem object
objMenuItem.Text = objWebFavorite.Name;
objMenuItem.Tag = objWebFavorite.Url;
// Add a handler to Click event of new menu item
objMenuItem.Click +=
new EventHandler(MenuItems_Click);
// Add the ToolStripMenuItem object
// to the ContextMenu
FavoritesMenu.Items.Add(objMenuItem);
}
private void MenuItems_Click(object sender,
System.EventArgs e)
{
// Create a ToolStripMenuItem
// and fill it with sender parameter
ToolStripMenuItem s = (ToolStripMenuItem)sender;
// Open the internet explorer to view selected
// favorite
System.Diagnostics.Process.Start(s.Tag.ToString());
}
private void ExitMenuItem_Click(object sender,
System.EventArgs e)
{
Application.Exit();
}
You do not have a closing brace for the icnNotify_Click
function.
精彩评论