OK我有一個字符串列表(實際上是文件名),我想創建一個文件菜單動態表單。在運行時添加到strip菜單
所以把我的文件名,目錄字符串和文件sufix的第一個碼片的列表(獎金問題我怎麼能換兩個上的刪除線,以一個?)
List<string> test_ = populate.Directorylist();
foreach (var file_ in test_)
{
int len_ = file_.Length;
string filename_ = file_.Remove(0, 8);
filename_ = filename_.Remove(filename_.Length - 4).Trim();
ToolStripItem subItem = new ToolStripMenuItem(filename_);
subItem.Click += new EventHandler(populate.openconfig(file_)); //this is my problem line
templatesToolStripMenuItem.DropDownItems.Add(subItem);
所以,簡單地循環通過列表並將每個項目添加到「templatesToolStripMenuItem」。
但我需要添加一個事件,當用戶單擊該項目時,它將file_ varible發送到populate.openconfig方法。
所以添加項目工作正常,我該如何添加事件處理?
我想我可以將它發送到一個默認的方法,在原始數組中搜索完整的文件名,並按照這種方式。但當然,我可以做到這一點,因爲我將項目添加到菜單欄。
謝謝
亞倫
所以,是的,最後我加入
subItem.tag = File_
....
then have the event handle to
void subItem_Click (object sender, EventArgs e) //open files from menu
{
ToolStripMenuItem toolstripItem = (ToolStripMenuItem)sender;
string filename_ = toolstripItem.Tag.ToString(); //use the tag field
populate.openconfig(filename_);
populate.Split(_arrayLists); //pass read varible dictonary to populate class to further splitting in to sections.
Populatetitle();//Next we need to populate the Titles fields and datagrid view that users will enter in the Values
}
和剛剛看到我如何能更是整理了一下:)
乾杯的幫助球員,只是愛你有多少種方式可以皮膚貓:)
希望Path類回答您的獎金問題http://msdn.microsoft.com/en-us/library/system.io.path_methods.aspx – CharithJ