在文本框控件的选择周围插入文本
Insert text around Selection of TextBox control
我想在 TextBox
控件的选择周围插入文本。
我试过这个:
if (textBox1.SelectionLength > 0)
{
object userclipboard = new object();
userclipboard = Clipboard.GetDataObject;
textBox1.Copy();
string textCopied = Clipboard.GetTextObject;
string finalString = "text" + textCopied + "more text";
textBox1.Paste();
Clipboard.SetDataObject(userclipboard);
}
但是不行。
我哪里做错了?
使用Clipboard.GetText()
从剪贴板粘贴值,Clipboard.SetText(finalString);
复制值
string textCopied = Clipboard.GetText();
string finalString = "text" + textCopied + "more text";
Clipboard.SetText(finalString);
textBox1.Text = Clipboard.GetText();
如果您想使用 TextBox
属性从文本框中复制选择文本
string textCopied = textBox1.SelectedText; // To get the selected text from textbox1
string finalString = "text" + textCopied + "more text";
Clipboard.SetText(finalString);
textBox1.Paste();
textBox1.Copy();
将复制您的选择文本,如 Clipboard.SetText(finalString);
我想在 TextBox
控件的选择周围插入文本。
我试过这个:
if (textBox1.SelectionLength > 0)
{
object userclipboard = new object();
userclipboard = Clipboard.GetDataObject;
textBox1.Copy();
string textCopied = Clipboard.GetTextObject;
string finalString = "text" + textCopied + "more text";
textBox1.Paste();
Clipboard.SetDataObject(userclipboard);
}
但是不行。
我哪里做错了?
使用Clipboard.GetText()
从剪贴板粘贴值,Clipboard.SetText(finalString);
复制值
string textCopied = Clipboard.GetText();
string finalString = "text" + textCopied + "more text";
Clipboard.SetText(finalString);
textBox1.Text = Clipboard.GetText();
如果您想使用 TextBox
属性从文本框中复制选择文本
string textCopied = textBox1.SelectedText; // To get the selected text from textbox1
string finalString = "text" + textCopied + "more text";
Clipboard.SetText(finalString);
textBox1.Paste();
textBox1.Copy();
将复制您的选择文本,如 Clipboard.SetText(finalString);