vb.net - 如何从richtextbox中的每一行获取值并将每个值显示到文本框中

时间:2018-06-13 08:11:41

标签: vb.net

我的代码中有一个问题,问题是 如何从richtextbox中的每一行获取值并将每个值显示到文本框中?

我的代码是:

Imports System.IO

Public Class Form1
Private Results As String
Private Sub UpdateText()
    Dim xList As New List(Of KeyValuePair(Of String, String))
    Results = Results.Replace(vbLf, "")
    Dim LineSplit() As String = Results.Split(vbCr)
    For Each xLine As String In LineSplit
        If xLine <> "" Then
            xList.Add(New KeyValuePair(Of String, String)(xLine.Split("=")(0), xLine.Split("=")(1).Trim.Replace(" ", "")))
        End If
    Next
    'do some work here to put the values in the right textboxes


End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    UpdateText()
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Results = RichTextBox1.Text
End Sub
End Class

Example Picture

抱歉我的英语不好,我来自印度尼西亚,谢谢......

1 个答案:

答案 0 :(得分:0)

而不是List,你可以遍历文本框类型的控件。

如果行数总是等于文本框的数量,你可以在你的行或文本框上循环,或者甚至为x = 0到11做静态,那么只需将行x放入文本框x。

由于我们不知道您如何命名这些文本框,我将向您展示一种适合您的方式:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim counter As Integer
    For Each controlOnForm In Me.Controls
        If TypeOf controlOnForm Is TextBox Then
            if counter <12 then 'depending how you ordered them you may need to fix this sign
                controlOnForm.text = TextBox1.Lines(counter).Split("=")(1)
                counter += 1
            end if
        End If
    Next
End Sub