You can get the selected text of a TextBox
through the property SelectedText
.
You can put something on the clipboard using the static method:
Clipboard.SetText(textBox1.SelectedText);
And get text from the clipboard (also the one copied into the clipboard in the browser) with:
if (Clipboard.ContainsText()) {
textBox1.Text = Clipboard.GetText();
}
See: Clipboard Class.
If you only want to do that on the current form, you can get the current control with the form property ActiveControl
. But will have to use different methods for different types of controls in order to get the selected text. Controls deriving from TextBoxBase
have a SelectedText
property. All controls have a Text
property. All controls deriving from ListControl
(like ComboBox
) have a SelectedValue
property. ComboBox
has a SelectedItem
property.
As you can see, you will have to make experiments and find the strategy which works best.
Also have a look into the Object Browser of Visual Studio, especially into the namespace System.Windows.Forms
.