How to copy selected text

i am trying to do cut and paste using ctrl ^x  and ctrl^v from my form. i want to copy selected text but . here is the code that i use.

 if (this.ActiveMdiChild.ActiveControl is BMWFSAM.Cafe.Desktop.Controls.TextBox)
            {
                Clipboard.Clear();
               
                Clipboard.SetDataObject(this.ActiveMdiChild.ActiveControl.Text.ToString());
                this.ActiveMdiChild.ActiveControl.Text = "";  
            }

this allows me to copy the entire text from the textbox but I want to do selectedbox . I cannot find .SelectedText property over here . is there anything else that i can use to cut selected text.
pratikshahseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Expert1701Commented:
What is BMWFSAM.Cafe.Desktop.Controls.TextBox?  Does it have SelectionStart or SelectionLength methods?  Could you use SendKeys.Send("^X")?
0
pratikshahseAuthor Commented:
Its just a regular textbox. and no it does not have selectionstart or selectionlength
0
Expert1701Commented:
If your control is just a regular textbox (i.e. it inherits from System.Windows.Forms.TextBox), then the following should work.
  if (this.ActiveMdiChild.ActiveControl is BMWFSAM.Cafe.Desktop.Controls.TextBox)
  {
    BMWFSAM.Cafe.Desktop.Controls.TextBox textBox = (BMWFSAM.Cafe.Desktop.Controls.TextBox)this.ActiveMdiChild.ActiveControl;
 
    Clipboard.Clear();
    Clipboard.SetDataObject(textBox.SelectedText);
    textBox.SelectedText = "";
  }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.