Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

text box read only

Tags:

c#

.net

textbox

i create form with TextBox on it. Text box have a ReadOnly true propertiy. when i add text to text box. all text inside the text box is selected. how i can rid that. i tried to change value of SelectionLength, SelectionStart, SelectedText properties but that did not help. I Use VC# 2008 express.

like image 551
Xaver Avatar asked Jul 25 '26 12:07

Xaver


1 Answers

After you set the text, clear the selection:

textBox1.Text += "String" + Environment.NewLine + "String";
textBox1.Select(0, 0);

SelectionLength will be 0 until after the TextBox receives focus, which explains why setting that property did not work.

like image 182
Jeff Ogata Avatar answered Jul 27 '26 03:07

Jeff Ogata



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!