朋友们,我应该在哪里定义FavoriteMenu来处理这段代码? 因为它给出错误:当前上下文中不存在名称'FavoritesMenu'
我解决了上面的问题,我没有为它定义一个contextMenuStrip。当我定义时,问题解决但现在说在当前上下文中不存在名称'MenuItems_Click'。我应该在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
objFavorites.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();
}
答案 0 :(得分:0)
使用完全访问路径,否则如(using namespace.class.components *name* =new namespace.class.components)
状态,请参考using
的msdn,因为仅仅使对象不能访问其内部成员。
只有在此类定义之后,您才能使用 name.X.Y
等。