-2
朋友,我应该在哪里定义FavoriteMenu以使用此代码? becouse提示错误:“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();
}
难道不是需要什么东西在你的其他类引用UI控件,例如在你的表单设计师? – Rup 2010-08-29 21:04:42
我不明白你说什么。你解释我说什么?最新的UI控制? – Arash 2010-08-29 21:07:22
你从哪里找到这段代码?你为什么期望它自行工作? – 2010-08-29 21:09:06