2017-04-06 76 views
0

我如何將數據從我在userControl中打開的表單傳遞迴userControl? 用戶控件代碼:Winforms如何將數據從表單傳遞迴用戶控件?

public AdminControl() 
    { 
     InitializeComponent(); 
     SetGridColomns(); 
    } 
private void btnEditInfo_Click(object sender, EventArgs e) 
    { 
     Form editForm = new EditForm(); 

     if (editForm.ShowDialog() == DialogResult.OK) 
     { 
     // trying to get Owner2 here but failing 
     } 
    } 

表格代號:

public partial class EditForm : Form 
{ 

    public CompanyOwner Owner2; 
    public EditForm() 
    { 
     InitializeComponent(); 
     Owner2 = new CompanyOwner(); 

    } 
    private void btnSave_Click(object sender, EventArgs e) 
    { 
     Owner2.Address = tbAddress.Text; 
     Owner2.CompanyName = tbCompanyName.Text; 
     Owner2.Email = tbEmail.Text; 
     Owner2.Phone = tbPhone.Text; 
    } 
} 

當我試圖讓editForm.Owner2什麼也不顯示。我試圖使它靜態,使用字符串而不是類,仍然沒有。我哪裏錯了?

回答

2

NVM我發現其中的錯誤......我應該使用EditForm而不是形式:

EditForm editForm = new EditForm(); 
相關問題