我知道如何使用构造函数将对象从父窗体传递到子窗体。通过属性将对象从父窗体传递给子窗体(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);
}
}
我还在试图获得属性的窍门......我会怎么使用属性而不是重载的构造函数来做到这一点?