1
我試圖通過單擊樹視圖節點來加載窗體。下面的代碼正在工作,但現在我需要將一些變量傳遞給加載表單。那麼當從樹視圖加載表單時,是否有一種方法可以傳遞變量。將變量傳遞給窗體,同時從樹視圖加載它們
string item = Convert.ToString(treeView1.SelectedNode);
int index = item.IndexOf(" ");
if (index > 0)
item = item.Substring(index + 1);
//MessageBox.Show(item);
var selectedFRM = from Menu in dbdata.Menus
where Menu.Item_Name == item
select Menu;
foreach (var pick in selectedFRM.Take(1))
{
string sel = pick.Form_Name;
//Assembly asm = typeof(frmUser).Assembly;
Assembly asm = typeof(frmCustomer).Assembly;
Type type = asm.GetType("WindowsFormsApplication6." + sel);
AssemblyName assemName = asm.GetName();
// MessageBox.Show(assemName.Name);
try
{
Form frmChk = (Form)Activator.CreateInstance(type);
//frmChk cgh = new frmChk();
frmChk.Show();
}
catch (Exception)
{
MessageBox.Show("Error in loading form");
}
}