我使用委託在兩個表格之間傳遞數據 MainForm;如何在2表單之間傳遞數據?
public delegate void PassData(ListViewItem itemss);
public PassData passdata;
private void ViewList_SelectedIndexChanged(object sender, EventArgs e)
{
passdata(ViewList.FocusedItem);
}
call PropertiesForm
Properties1 pro = new Properties1();
pro.Show();
在窗口2
public void f_pass(ListViewItem item)
{
this.item = item;
}
private void Properties1_Load(object sender, EventArgs e)
{
Main main = new Main();
main.passdata += new Main.PassData(f_pass);
}
當運行它有一個錯誤是在passdata(ViewList.FocusedItem)null對象;
當你調用passdata()。你可以告訴我一些更多的細節 – 2011-04-24 19:08:18
我調用passwata(ViewList.FocusedItem)在主窗體的私人無效ViewList_SelectedIndexChanged – giaosudau 2011-04-24 19:11:19
可能重複的[在winforms之間傳遞變量](http://stackoverflow.com/questions/4247807/passing-variable-在-Winforms之間) – 2011-04-24 19:18:21