0

我有这个:

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;
4

1 回答 1

1

而不是调用基类构造函数:

public FrmUpload(Dictionary<string, string> ft) : base()

调用您自己的无参数构造函数:

public FrmUpload(Dictionary<string, string> ft) : this()
于 2012-12-08T07:02:51.820 回答