OpenFileDialog1.Filter = "Text files (*.TXT)|*.TXT"
OpenFileDialog1.ShowDialog()
'display Open dialog box If OpenFileDialog1.FileName <> "" Then Try 'open file and trap any errors using handlerFileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
Do Until EOF(1) 'read lines from fileLineOfText = LineInput(1)
'add each line to the AllText variableAllText = AllText & LineOfText & vbCrLf
LooplblNote.Text = OpenFileDialog1.FileName
'update labeltxtNote.Text = AllText
'display filetxtNote.Select(1, 0)
'remove text selection:WHAT DOES IT MEAN Whwat is the selection and what does mean 1,0txtNote.Enabled =
True 'allow text cursormnuCloseItem.Enabled =
True 'enable Close commandmnuOpenItem.Enabled =
False 'disable Open command CatchMsgBox("Error opening file.")
FinallyFileClose(1)
'close file End Try End If End Sub
select method:I don't understand what is .select(1,0) 1? 0? select?
Shahzad Godil
From help:
"You can programmatically move the caret within the text box by setting the start parameter to the position within the text box where you want the caret to move to and set the length parameter to a value of zero (0). The text box must have focus in order for the caret to be moved."
So what it does is to set start position of caret (text cursor) to 1 (beginning) and select 0 characters (no selection). However it is unnecessary there (there are other unnecessary code like a loop). Instead you could do something like this:
OpenFileDialog1.Filter =
"Text files (*.TXT)|*.TXT"OpenFileDialog1.ShowDialog() 'display Open dialog box
If OpenFileDialog1.FileName <> "" Then
lblNote.Text = OpenFileDialog1.FileName 'update label
Try
txtNote.Text = System.IO.File.ReadAllText(OpenFileDialog1.FileName)
Catch
MsgBox("Error opening file.")
End Try
End If
Rahul Singla
I'm not sure where you got this code from but this will not work and the select statement will have no effect.
What it looks like is that you load the contents of the file into the textbox and the idea would be to enable the textbox with the carat in the textbox at the start. However this would not work with the select statement here as the textbox control (txtNote) does not specifically have the focus and that is required for the select statement to work.
That said, you could simply put the following statement into you code to ensure the control gets focus as the select statement implies that it requires focus to show any effect.
TxtNote.Focus
But I'd personally eliminate the two lines altogether, or replace with a single line
TxtNote.SelectionStart = 0
When this will come into play is if you carry out the action and tab through the controls to give the textbox focus - which will result in the (Carat) being at the start of the textbox. Otherwise if you click on the textbox the carat would be around the position you click in the textbox.
If you dont have any lines in then the carat will be at the end of the textbox contents.
Either way, it really only comes into play when your textbox gets the focus (either programmatically or through setting by tabbing)
Kyle Key