我有这个:
public partial class FrmUpload : Form
{
public FrmUpload()
{
InitializeComponent();
}
public FrmUpload(Dictionary<string, string> ft) : base()
{
foreach (KeyValuePair<string, string> ctrl in ft)
{
Controls.Find(ctrl.Key, true)[0].Text = ctrl.Value;
}
}
private void BtnCancelClick(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void BtnExitClick(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
Close();
}
}
我尝试这个时收到索引异常。如果我调试它,我看到InitializeComponent()不运行..
我主应用中的代码:
var frmUpload = new FrmUpload(FormTextUpload);
if (frmUpload.ShowDialog() != DialogResult.OK) return;
答案 0 :(得分:1)
而不是调用基类构造函数:
public FrmUpload(Dictionary<string, string> ft) : base()
调用您自己的无参数构造函数:
public FrmUpload(Dictionary<string, string> ft) : this()