定义问题 [英] defining problem
问题描述
朋友们,我应该在哪里定义FavoriteMenu来运行这段代码?因为它给出了错误:当前上下文中不存在名称FavoritesMenu"
friends,where should i define FavoriteMenu to work this code? becouse it gives error:The name 'FavoritesMenu' does not exist in the current context
我解决了上述问题,我没有为其定义 contextMenuStrip.当我定义时,该问题解决了,但现在说当前上下文中不存在名称MenuItems_Click".我应该在 ContextMenuStrip 的任何地方命名它吗?谢谢
i solved above problem,i didnt define a contextMenuStrip for it.when i defined,that problem solved but now say The name 'MenuItems_Click' does not exist in the current context. should i named it anywhere in ContextMenuStrip?thanks
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();
}
推荐答案
use full access path else state like (using namespace.class.components *name* =new namespace.class.components)
,using
参考 msdn,因为仅仅创建一个对象并不能访问其内部成员.
use full access path otherwise state like (using namespace.class.components *name* =new namespace.class.components)
,refer msdn for using
,because merely making an object doesnt give access to its internal member.
只有经过这种类型的定义,你才能使用name.X.Y
等
only after this type of definition, u can use name.X.Y
etc.
这篇关于定义问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!