大家好,我想在一个WinForm的TabPage
上添加一个自定义的RichTextBox
。我尝试了下面代码中所示的各种方法。
TabPage tmpTabPage = new TabPage("Test");
tabControl1.TabPages.Add(tmpTabPage);
CustomRichTextBox tmpRichTextBox = new CustomRichTextBox();
tmpRichTextBox.LoadFile(@"F:\aaData\IPACostData\R14TData\ACT0\1CALAEOSAudit_log.rtxt");
// Attempted FIX.
tabControl1.SuspendLayout();
tabControl1.TabPages["Test"].Controls.Add(tmpRichTextBox); // This throws a NullReferenceException??
tabControl1.ResumeLayout();
tmpRichTextBox.Parent = this.tabControl1.TabPages["test"];
tmpRichTextBox.WordWrap = tmpRichTextBox.DetectUrls = false;
tmpRichTextBox.Font = new Font("Consolas", 7.8f);
tmpRichTextBox.Dock = DockStyle.Fill;
tmpRichTextBox.BringToFront();
在我添加"aAttempted FIX"之前,代码可以正常运行,但是
CustomRichTextBox
不会出现。现在我得到了NullReferenceException
,对这两种情况都感到困惑。我在这里做错了什么?