未将对象引用设置到对象实例。
这怎么解决阿?
执行
textUserName.Text=((MainForm)this.ParentForm).UserName;
时发生。

解决方案 »

  1.   

    this.ParentForm 估计是空,把相关代码都拿出来看看阿
      

  2.   

    我觉得开始你已经定义了父子关系,
    子窗体.textUserName.text=父窗体.UserName;
      

  3.   

    UserName是什么,public的变量还是属性,建议不要使用public 变量
      

  4.   

    UserName是public
    创建子窗体体用的是setWindow=new ConnectSet();
    setWindow.ShowDialog(this);
    setWindow=null;
      

  5.   

    setWindow=new ConnectSet();
    setWindow.ShowDialog(this);
    setWindow=null;
    看不懂你的代碼
      

  6.   

    当你用ShowDialog的时候,不应该使用ParentForm来获取父窗体,而应该用Owner:
    textUserName.Text=((MainForm)this.Owner).UserName;