在文本框中显示光标指向的行并隐藏VB.NET中的其他行 [英] Display cursor pointed line in textbox and hide other lines in VB.NET

查看:146
本文介绍了在文本框中显示光标指向的行并隐藏VB.NET中的其他行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法只显示单行文本文件,当光标/键向上和向下完成时加载到文本框中,并在当前行突出显示时隐藏其他行。



示例:

文本框中的两行文本文件是:



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

推荐答案

参考讨论到现在为止我会建议以下:

- with加载表单(例如),将文本文件的数据加载到数组中(就像已经发布的那样)。

还将第一个数组元素分配给文本框

构建索引变量(整数),它指向已经可以看到的行

- 现在将KeyUp-Event从文本框挂钩到一个减少索引变量的方法(和检查它对阵Array-Bounds)。

将由此变量索引的Array-Element分配给你的Textbox

- 现在将KeyDown-Event从Textbox挂钩到一种增加Index-Variable的方法(并根据Array-Bounds检查)。

将由此变量索引的Array-Element分配给文本框



Refering to the discussion until now I would suggest the Following :
- with Loading your Form (for example) you load the Data of your Textfile into an Array (like allready posted from you).
Also assign the 1st Array-Element to your Textbox
Build an Index-Variable (Integer) which points to the line which is allready to be seen
- now hook the KeyUp-Event from the Textbox to a method where you decrease the Index-Variable (and check it against the Array-Bounds).
Assign the Array-Element which is indexed by this Variable to your Textbox
- now hook the KeyDown-Event from the Textbox to a method where you increase the Index-Variable (and check it against the Array-Bounds).
Assign the Array-Element which is indexed by this Variable to your Textbox

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中的其他行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆