[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1739
  • Last Modified:

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.
0
pratikshahse
Asked:
pratikshahse
  • 2
1 Solution
 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now