我知道如何使用構造函數將對象從父窗體傳遞到子窗體。通過屬性將對象從父窗體傳遞給子窗體(Winforms)
例如,在父窗體,我這樣做:
WithdrawDialog dlg = new WithdrawDialog(cust.Accounts);
子窗體:
public WithdrawDialog(BankAccountCollection accounts)
{
InitializeComponent();
PopulateComboBox(accounts);
}
// populate comboBox with accounts
private void PopulateComboBox(BankAccountCollection accounts)
{
foreach (BankAccount b in accounts)
{
comboBoxAccount.Items.Add(b);
}
}
我還在試圖獲得屬性的竅門......我會怎麼使用屬性而不是重載的構造函數來做到這一點?