净
我正在尝试创建一个允许用户将文本输入RTB的函数,如果该文本作为键存在于Dictionary中,则所有listbox
填充values
与dictionary
相关联的key
,每个value
在新行中填充listbox
。
第一行突出显示,用户可以按enter button
并用突出显示的文本替换RTB中的文本。
我是VB的新手,所以我不太了解。
这是我到目前为止所做的。
Public Class Oxnay
Private Sub Oxnay_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Tsort()
End Sub
Private TDictionary As Dictionary(Of String, String())
Public Sub Tsort()
TDictionary = New Dictionary(Of String, String())
TDictionary.Add("ape", {"pl", "tz", "xu"})
TDictionary.Add("lor", {"tv", "px"})
End Sub
Private Sub RichtextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged
Dim lastword As String = RichTextBox1.Text.Split(" ").Last
If RichTextBox1.ContainsKey(lastword) Then
'display each string of the dictionary array related to lastword in different lines
'highlight first line
'Some[Code]
Else
ListBox1.Text = ""
End If
End Sub
结束班
答案 0 :(得分:1)
对于第一个“查找”部分,尝试类似:
Private Sub RichtextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged
Dim lastword As String = RichTextBox1.Text.Trim.Split(" ").Last
ListBox1.Items.Clear()
If Not IsNothing(TDictionary) AndAlso TDictionary.ContainsKey(lastword) Then
ListBox1.Items.AddRange(TDictionary(lastword))
End If
End Sub
然后使用ListBox中的选择替换当前选定的文本:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If ListBox1.SelectedIndex <> -1 Then
If RichTextBox1.SelectedText <> "" Then
RichTextBox1.SelectedText = ListBox1.SelectedItem.ToString
End If
End If
End Sub