I have one tab with the richtextbox control. I have a "New" button. What code should I add to the button, so when the user presses it, a new tabpage is added to the tabcontrol, and the richtextbox is added to the new tabpage.
Depending on what you are intending to do you may find it beneficial to do something like this:
public class RichTextBoxTabPage: TabPage { public RichTextBox TextBox = new RichTextBox(); public RichTextBoxTabPage() { TextBox.Dock = DockStyle.Fill; this.Controls.Add(TextBox); } }
This is useful as you can keep the tap page and its text box together and easily manageable, if you ever want to add more things to your tab page you can do it in this RichTextBoxTabPage class. If you want to access the tab page after it has been added to the tab control:
RichTextBoxTabPage tp = (RichTextBoxTabPage)myTabControl.TabPages[0]; tp.TextBox.AppendText("This will appear in the richtextbox");
Tab question
akula hari
Depending on what you are intending to do you may find it beneficial to do something like this:
public class RichTextBoxTabPage: TabPage
{
public RichTextBox TextBox = new RichTextBox();
public RichTextBoxTabPage()
{
TextBox.Dock = DockStyle.Fill;
this.Controls.Add(TextBox);
}
}
.....
private void ButtonPressCodeHere()
{
RichTextBoxTabPage tp = new RichTextBoxTabPage();
myTabControl.TabPages.Add(tp);
}
This is useful as you can keep the tap page and its text box together and easily manageable, if you ever want to add more things to your tab page you can do it in this RichTextBoxTabPage class. If you want to access the tab page after it has been added to the tab control:
RichTextBoxTabPage tp = (RichTextBoxTabPage)myTabControl.TabPages[0];
tp.TextBox.AppendText("This will appear in the richtextbox");
Hope that helps
Sudha__
try this code:
TabPage
tp = new TabPage(); RichTextBox rt = new RichTextBox();rt.Parent = tp;
rt.Dock =
DockStyle.Fill;myTabControl.TabPages.Add(tp);