我已将一些项目动态添加到我的菜单条中,并为添加到条中的每个项目触发和事件(项目是从 XML 文件添加的)。我接下来要做的是将每个项目的文本传递给事件处理程序,以便我可以在线程中使用它们。这有可能吗?任何人都可以帮我解决问题吗?
这是我的代码:
private void historyMenuItem_Click(object sender, EventArgs e){
XmlDocument doc = new XmlDocument(); // create new xml document
doc.Load("..\\history.xml"); // load the xml
// create a new node list
// and select nodes from BookItems/Book
XmlNodeList nodeList = doc.SelectNodes("URLs/http");
historyMenuItem.DropDownItems.Clear();
foreach (XmlNode node in nodeList) {
string page = node.Attributes["page"].Value;
//http://msdn.microsoft.com/en-us/library/ms160990.aspx
ToolStripMenuItem windowNewMenu = new ToolStripMenuItem(page, null, new EventHandler(MenuItemClickHandler));
historyMenuItem.DropDownItems.Add(windowNewMenu);
}
}
private void MenuItemClickHandler(object sender, EventArgs e){
ToolStripMenuItem clickedItem = (ToolStripMenuItem)sender;
## HERE IS WHERE I NEED HELP:
UrlTextBox = (I need value of page here!);
this.thread = new Thread(new ThreadStart(this.httpRequestMultiThread));
this.thread.Start();
}