问题描述
是否有任何方法只显示单行文本文件,当光标/键向上和向下完成时加载到文本框中,并在当前行突出显示时隐藏其他行。
示例:
文本框中的两行文本文件是:
abcdef
1234
当光标指向包含abcdef的行时,然后包含1234的行应该隐藏文本文件的第二行,当光标在第二行然后是第一行和其他文本框的行应该隐藏
我尝试过:
Private Sub Form1_Load(sender As Object,e As EventArgs)Handles MyBase.Load
Dim ReadSpciFile As Array
Dim line As String
ReadSpciFile = File.ReadAllLines(C:\ Users \OM\Desktop\1(3).txt)
line = ReadSpciFile(0)
RichTextBox1。 Text = line
结束Sub
以上代码现在显示第一行文本文件由于这个line = ReadSpciFile(0)
但是我无法加载/看到其他行当我的keydown / keyup事件
Is there any method to display only single line of textfile which is loaded in textbox when cursor/key up&down is done and hide other lines while current line is highlighted.
Example:
Two lines of textfile in textbox are:
abcdef
1234
when cursor is pointed on line containing "abcdef" then line containing "1234" which is second line of textfile should be hide and when cursor is on second line then first and other lines of textbox should be hide
What I have tried:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim ReadSpciFile As Array
Dim line As String
ReadSpciFile = File.ReadAllLines("C:\Users\OM\Desktop\1 (3).txt")
line = ReadSpciFile(0)
RichTextBox1.Text = line
End Sub
above code is now showing first line of textfile due to this "line = ReadSpciFile(0)"
but i am unable to load/see other lines when i keydown/keyup event
推荐答案
Dim ReadSpciFile As array
Dim Index as integer = 0
Private Sub Form1_Load (sender As Object, e As EventArgs) Handles MyBase.Load
Dim line As String
ReadSpciFile = File.ReadAllLines("C:\Users\OM\Desktop\1 (3).txt")
line = ReadSpciFile(0)
RichTextBox1.Text = line
End Sub
private sub DecreaseLine (sender As Object, e As EventArgs) Handles RichTextBox1.KeyUp
Index -= 1
if Index < 0 then Index = 0
line = ReadSpciFile(Index)
RichTextBox1.Text = line
end sub
private sub IncreaseLine (sender As Object, e As EventArgs) Handles RichTextBox1.KeyDown
Index += 1
if Index >= ReadSpciFile.length then Index = ReadSpciFile.length
line = ReadSpciFile(Index)
RichTextBox1.Text = line
end sub
扩展建议:
Extended suggestion :
Dim ReadSpciFile As array
Dim Index1 as integer = 0
Dim Index2 as integer = 0
Private Sub Form1_Load (sender As Object, e As EventArgs) Handles MyBase.Load
Dim line As String
ReadSpciFile = File.ReadAllLines("C:\Users\OM\Desktop\1 (3).txt")
line = ReadSpciFile(0)
RichTextBox1.Text = line
End Sub
private sub DecreaseLine1 (sender As Object, e As EventArgs) Handles RichTextBox1.KeyUp
Index1 -= 1
if Index1 < 0 then Index1 = 0
line = ReadSpciFile(Index1)
RichTextBox1.Text = line
end sub
private sub IncreaseLine1 (sender As Object, e As EventArgs) Handles RichTextBox1.KeyDown
Index1 += 1
if Index1 >= ReadSpciFile.length then Index1 = ReadSpciFile.length
line = ReadSpciFile(Index1)
RichTextBox1.Text = line
end sub
private sub DecreaseLine2 (sender As Object, e As EventArgs) Handles RichTextBox2.KeyUp
Index2 -= 1
if Index2 < 0 then Index2 = 0
line = ReadSpciFile(Index2)
RichTextBox2.Text = line
end sub
private sub IncreaseLine2 (sender As Object, e As EventArgs) Handles RichTextBox2.KeyDown
Index2 += 1
if Index2 >= ReadSpciFile.length then Index2 = ReadSpciFile.length
line = ReadSpciFile(Index2)
RichTextBox2.Text = line
end sub
这篇关于在文本框中显示光标指向的行并隐藏VB.NET中的其他行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!