在Form1.cs中我有C#打開窗體從另一個形狀誤差
public const int n = 30;
public TabPage[] tp = new TabPage[n];
private void toolStripSeparator1_Click(object sender, EventArgs e)
{
RenameFunc rf = new RenameFunc();
rf.ShowDialog();
}
在RenameFunc.cs我有
private void button1_Click_1(object sender, EventArgs e)
{
Form1 frm1 = new Form1();
if (textBox1.Text != null)
/*Line 24 */ frm1.tp[Array.IndexOf(frm1.tp, frm1.tabControl1.SelectedTab)].Text = textBox1.Text;
Application.Exit();
}
tabControl1也seted TU公開
行24我得到錯誤
System.NullReferenceException:對象引用未設置爲對象的實例。 at System.Windows.Forms.TabControl.get_SelectedTabInternal() at System.Windows.Forms.TabControl.get_SelectedTab() at Notepad1._0.RenameFunc.button1_Click_1(Object sender,EventArgs e)in D:\ C#\ Notepad1。 0 \ Notepad1.0 \ RenameFunc.cs:line 24
如何更正?
你正在隱藏一些東西。 :)什麼是'frm1.tp'?你爲什麼要創建一個'Form1'的新實例? – J0HN
我會建議你不要直接訪問RenameFunc.cs中的tabControl。您應該在Form1.cs中實現一個Property,其中包含Tabcontrol的選定Tab。 – Tomtom