0
我有一個用戶控件,應該將值傳遞給它的父窗體form1。如何將用戶控件的值傳遞給父窗體?
我使用下面的代碼。
用戶控制
public int _control;
public int control
{
get{return _control;}
set{_control=value;}
}
Form1中值分配給用戶控件
UserControl1 uc=new UserControl1();
uc.control=1;
用戶控制Button_Click
var parent = this.Parent as Form1;
//MessageBox.Show(_control.ToString());
parent.userNo=_control;
Form1中
public int _userNo;
public int userNo
{
get{return _userNo;}
set{_userNo=value;}
}
問題是,當我用messagebox.show,它會出現顯示1但是當我使用
parent.userNo=_control;
它返回一個空引用異常。
請幫忙!!!
的可能重複[?什麼是一個NullReferenceException,我如何修復它(http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how- do-i-fix-it) – Sinatr 2014-12-03 09:48:33