I have few TabPages and each contains rich text box. How can I access richtechbox on a selected tab?
TabPage selectedTab = tabControl.SelectedTab;
RichTextBox selectedRtb = selectedTab.Controls.Find("rtb", true).First() as RichTextBox;
This is what I have tried but no luck.
Added:
This is how tabpage is added with richtextbox control
TabPage newTab = new TabPage(name);
RichTextBox rtb = new RichTextBox();
rtb.Dock = DockStyle.Fill;
rtb.BorderStyle = BorderStyle.None;
rtb.Text = file.Data;
newTab.Controls.Add(rtb);
tabControl.TabPages.Add(newTab);
tabControl.SelectedTab = newTab;
If this is WinForms, it would just be:
if rtb is the name of the RichTextBox control.
When creating your control, add the name to it: