Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to paste text in textbox current cursor?

Tags:

c#

textbox

How do you paste text into a TextBox at the current cursor position in Windows Forms?

Not textbox1 += string

like image 619
monkey_boys Avatar asked Sep 12 '09 23:09

monkey_boys


People also ask

How do you insert text into the input at the current cursor position?

First, get the current position of cursor with the help of property named as selectionStart on textarea/inputbox. To insert the text at the given position we will use slice function to break the string into two parts and then we will append both parts to the text(text_to_insert) in front and end of the text.

How do you insert text into the textarea at the current cursor position react?

When you click a button you move the focused element so there is no cursor in the text anymore. So you would have to track the last location of the cursor and then just set the value of the text area to be the current value + the extra text at the location of the last know cursor position.

How do you start a new text section at the current cursor position without adding a new page?

Select where you want a new section to begin. Go to Layout > Breaks, and then choose the type of section break you want.

How to insert text in TextBox c#?

Step 1: Create a windows form. Step 2: Drag the TextBox control from the ToolBox and Drop it on the windows form. You can place TextBox anywhere on the windows form according to your need. Step 3: After drag and drop you will go to the properties of the TextBox control to set the Text property of the TextBox.


2 Answers

A much easier way would be to use the Paste method:

  textbox1.Paste("text to insert"); 

I've done this using .NET 4.0

like image 109
bsara Avatar answered Sep 28 '22 07:09

bsara


var insertText = "Text"; var selectionIndex = textBox1.SelectionStart; textBox1.Text = textBox1.Text.Insert(selectionIndex, insertText); textBox1.SelectionStart = selectionIndex + insertText.Length; 
like image 43
MNZ Avatar answered Sep 28 '22 08:09

MNZ