Reputation: 95
I asked a question here
and im unsure how to add the class the user gave me - I have just created a new class file then pasted in the class and i dont know how to apply that to the richtextbox?
Heres how my richtextbox is found... I have a richtextbox for each tabpage opened in my text editor i created a new textbox on the newtab void
public RichTextBox GetRichTextBox()
{
RichTextBox rtb = null;
TabPage starting = tabControl1.SelectedTab;
if (starting != null)
{
rtb = starting.Controls[0] as RichTextBox;
}
rtb.TextChanged += new EventHandler(txtBox_TextChanged);
rtb.MouseClick += new MouseEventHandler(rtbh_MouseClick);
//rtb.Select(rtb.Text.Length, 0);
rtb.Font = new Font(rtb.Font.FontFamily, 12);
rtb.Select(rtb.Text.Length, 0);
return rtb;
}
Upvotes: 0
Views: 1182
Reputation: 2204
The class the user gave you inherits from RichTextBox
- so when adding textboxes to your text editor, add this custom class. And for your function of finding textboxes, use the custom control. So change the above function to this:
public HighlightableRTB GetRichTextBox()
{
HighlightableRTB rtb = null;
TabPage starting = tabControl1.SelectedTab;
if (starting != null)
{
rtb = starting.Controls[0] as HighlightableRTB;
}
if (rtb != null)
{
rtb.TextChanged += new EventHandler(txtBox_TextChanged);
rtb.MouseClick += new MouseEventHandler(rtbh_MouseClick);
//rtb.Select(rtb.Text.Length, 0);
rtb.Font = new Font(rtb.Font.FontFamily, 12);
rtb.Select(rtb.Text.Length, 0);
}
return rtb;
}
The actual adding of the custom textbox should probably look something like this:
TabPage tabPage = new TabPage("Test");
tabPage.Name = "Test";
tabControl1.TabPages.Add(tabPage);
HighlightableRTB customTextBox = new HighlightableRTB();
tabControl1.TabPages["Test"].Controls.Add(customTextBox);
Upvotes: 1