I have a Form (Form2) that contains a Split Container, the RichTextBox is on the Left Panel and the WebBroswer is on the Right Panel.
I am showing the Form as a child of a MDIParent Form 1. What I wanted to do is copy the selected text of the active MDI Child. However due to the RichTextBox being inside a Split Container, I cannot target the RichTextBox and it returns nothing.
Form activeChild = this.ActiveMdiChild;
if (activeChild != null)
{
try
{
RichTextBox theBox = (RichTextBox)activeChild.ActiveControl;
if (theBox != null)
{
// Put the selected text on the Clipboard.
Clipboard.SetDataObject(theBox.SelectedText);
}
}
catch
{
MessageBox.Show("Unable to Copy to Clipboard");
}
}
The result is, the Message Box shows so that means I wasn't able to target the RTB properly. How can I get the current active RTB?