Reputation: 1001
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.
Upvotes: 2
Views: 7242
Reputation: 81
I need a little more information from you. Are you trying to disable the textbox (Read-only)? You can say "Textbox1.enabled = false"
Upvotes: 0
Reputation: 57823
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.
Upvotes: 5
Reputation: 6627
Setting the ReadOnly property to True should be enough. Maybe you have some other code that selects the text you programtically put into the textbox.
Upvotes: 1