Question Multiline textBox Question

inkedgfx

Well-known member
Joined
Sep 29, 2012
Messages
139
Location
USA
Programming Experience
Beginner
I have a multiline textbo that I load a txt file into at runtime...but when i do this all the text in the texbox is selected..how to stop this from happening?

here is the load code

Private HelpFile As String = "path"

then in the load event

If IO.File.Exists(HelpFile) then
txthelpView.Text = IO.File.ReadAllText(HelpFile)
Else
msgBox("Error Reading File!")
End If

thank You
InkedGFX
 
Hi,

The probable reason for this is one of two things:-

1) The textbox control that you have loaded the file into is the only control on the form and it therefore automatically gets the FOCUS (thus highlighting the text) after the form has loaded

2) If you have more than one control on the form the tab index of the textbox control is the lowest value in the controls collection and therefore gets the focus when the form loads.

There are a few ways you can get round this:-

1) Disable the textbox control - therefore the control cannot receive the focus and therefore cannot be highlighted

2) Change the textbox control to a label control - label controls cannot receive focus

3) Add additional controls to the form and change the tab index order to ensure the textbox is not the first control that receives the focus.

Hope that helps.

Cheers,

Ian
 
That's what happens when you set the Text property of the TextBox in code. Simply set the SelectionLength property to zero afterwards and the length of the selection will be zero, i.e. nothing will be selected.
 
Back
Top