2015-02-08 54 views
1

我希望以其他形式提供在登錄表單中輸入的用戶名。在form1的文本框中輸入的值不會傳遞給form2的標籤

Form1中:

private void BtnLogin_Click(object sender, EventArgs e) 
    { 
     ..... 

     FrmCreate_Invoice ci = new FrmCreate_Invoice(txtUsername.Text); 

     ..... 
    } 

窗體2:

public FrmCreate_Invoice(string usrnam) 
    { 
     InitializeComponent(); 
     string ausr = usrnam.ToString(); 
     label1.Text = ausr; 
    } 

}

+1

你在哪一行得到'NullReferenceException' – 2015-02-08 14:07:59

+0

我猜'label1'爲空?因爲如果是這樣,你需要在這行'label1.Text = ausr;'上取消對'InitializeComponent()'行 – Tomer 2015-02-08 14:09:22

+0

的註釋。 @尼古拉 – Ameena 2015-02-08 14:10:06

回答

0

你得到NullReferenceException因爲label1null

由於@Tomer建議,取消註釋InitializeComponent();

沒有InitializeComponent沒有組件將被初始化,因此它們的值將是null

+0

謝謝。在我取消註釋初始化組件行後,錯誤不再發生。但label.text值仍然是'label1':( – Ameena 2015-02-08 14:15:29

相關問題