我的代码中有一个问题,问题是
如何从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
很抱歉我的英语不好,我来自印度尼西亚,谢谢..
发布于 2018-06-16 07:44:27
你可以循环遍历Textbox类型的控件,而不是列表。
如果行数总是等于文本框的数目,你可以循环遍历你的行或文本框,或者甚至对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
https://stackoverflow.com/questions/50832202
复制相似问题