无法将值从用户控件传递到表单

时间:2019-07-19 03:47:17

标签: c# winforms

我正在尝试将类对象从用户控件传递到我的主窗体中,

在Form1

private Transaction _transaction = new Transaction();

public Transaction Transaction
{

    get { return _transaction; }
    set
    {
        _transaction.TollFee = value.TollFee;
        _transaction.TellerClass = value.TellerClass;
        _transaction.TellerId = value.TellerId;
        _transaction.TransactionDateTime = value.TransactionDateTime;
    }
}

在分类控制中

private void ChangeToClass1(object sender, EventArgs e)
{
    _tellerClass = 1;
    _tollFee = GetTollFee(_tellerClass);
    _transaction = new Transaction
    {
        TellerClass = _tellerClass,
        TellerId = "1001",
        TollFee = _tollFee,
        TransactionDateTime = DateTime.Now
    };
    var parent = this.Parent as Form1;
    parent.Transaction = _transaction;
    SetLabels();
}

在ClassificationControl的“ var parent = this.Parent as Form1;”行中我收到

的错误

“其他信息:对象引用未设置为对象的实例。”

您能告诉我发生了什么吗?谢谢。

0 个答案:

没有答案