Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1)First query: How to load line by line of textfile when keyboard up and down arrow is used


2)Second query: how to go up in the dynamic created textbox by pressing keyboard up and down arrow

What I have tried:

Public Class Form2


Private Sub openbtn_Click(sender As Object, e As EventArgs) Handles Button2.Click
'FIRST WORKING METHOD
If (OpenFileDialog1.ShowDialog = DialogResult.OK) Then
TextBox1.Text = OpenFileDialog1.FileName

End If

1)First query: How to load line by line of textfile when keyboard up and down arrow is used

For Each ln In IO.File.ReadLines(OpenFileDialog1.FileName)
Dim tb As New TextBox With {.Width = FlowLayoutPanel1.Width - 2, .Multiline = False, .Text = ln}
AddHandler tb.KeyDown, AddressOf TextBox_KeyDown
AddHandler tb.KeyUp, AddressOf TextBox_KeyUp
FlowLayoutPanel1.Controls.Add(tb)
tb.Margin = New Padding(15, 15, 15, 15)

Next



End Sub

Private Sub TextBox_KeyDown(sender As Object, e As KeyEventArgs)
If (e.KeyData = Keys.PageDown) Then
e.Handled = True
SendKeys.Send("{Tab}")
End If
End Sub

2)Second query: how to go up in the dynamic created textbox by pressing keyboard up and down arrow

Private Sub TextBox_KeyUp(sender As Object, e As KeyEventArgs)
If (e.KeyData = Keys.PageUp) Then
e.Handled = True
SendKeys.Send("{Tab}")
End If
End Sub

End Class
Posted
Comments
Richard MacCutchan 12-Apr-20 8:04am    
If you set Multiline=true, then the Textbox will do all the scrolling automatically.
shaileshshinde 12-Apr-20 10:16am    
Sorry I forgot to mention.

I need line by line in different textbox one by one.

If first line is displayed on first textbox then other textboxes should get hide and when key down on 2nd line then 1st and other lines should be hide.and same process for all textbox view.

Now I have managed to split all textfile lines in different textboxes from above code.
Richard MacCutchan 12-Apr-20 11:38am    
Sorry, but I cannot figure out exactly what you are trying to do.
shaileshshinde 12-Apr-20 12:53pm    
Ok.
There are n number of textfile lines.

Now from above code I have managed to split all lines in different textbox at a same time.(means all lines seen at same time)

But what I want is when file is loaded then first line is visible and when I click keyboard down arrow then only second textbox should get visible and other textboxes should be hide.

I hope now you have got my concern ?
Richard MacCutchan 12-Apr-20 13:15pm    
OK, then you should create an array of textbox references. Start with the first one visible and all the others invisible. Every time you get a keyboard event with the down arrow, hide the currently visible textbox, and show the next one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900