0
I have a textbox, and I need to get the content of the line where the cursor is positioned. For example, I am in the third line of the textbox (cursor positioned on it), I would like to get the contents of this line. I thank you already...
0
I have a textbox, and I need to get the content of the line where the cursor is positioned. For example, I am in the third line of the textbox (cursor positioned on it), I would like to get the contents of this line. I thank you already...
3
I imagine you have one TextBox
with the property MultLine
qualified to true
.
Thus, to obtain the contents of the line where the vertical bar is positioned | just use this method I created PegaConteudoDaLinhaAtual()
, see:
string PegaConteudoDaLinhaAtual(TextBox textBox)
{
var textoDaLinha = textBox.Lines[textBox.GetLineFromCharIndex(textBox.SelectionStart)].ToString();
return textoDaLinha;
}
Here is the implementation of it at the click of the button:
private void btnPega_Click(object sender, EventArgs e)
{
MessageBox.Show(PegaConteudoDaLinhaAtual(textBox1));
}
Thank you, Valeuzão. It helped a lot :)
Browser other questions tagged c# winforms textbox
You are not signed in. Login or sign up in order to post.
Is Windows Forms?
– Jéf Bueno
It is Windows Forms yes
– LocalHost
@Localhost ñ understood very well what q vc want, can not use the option
Copiar
? You could also show us what your code looks like and how you’re trying to do it?– gato
For example, I am in the third line of the textbox, moving with the arrow up or down, and if for example I am in that third line (cursor positioned in it), I would like to get the contents of that line, you know?
– LocalHost
The main issue that I’m failing to address is getting the content of the line on which I’m focusing
– LocalHost
@Localhost yes I think I understand, you want to get all the content from the line where the vertical bar is positioned | or just a word?
– gato
That, all the content.
– LocalHost