同步两个文本框行VB.Net

时间:2019-06-17 16:39:10

标签: vb.net

如何同步2个文本框?我的意思是,如果我将第一个文本框(随机化文本行)随机化,那么如何在第一个文本框之后同步第二个文本框?

IMG1 IMG2

我还希望将包含项目的4个文本框保存在(Answer.dat)中,例如,如果在第一个文本框中,我在第3个文本框中的第2个文本框元素(21)中具有元素(BlackJack),则在Poker元素中还有第四个Textbox元素Bingo。

我要将其保存在新行中(在我的文本文件中),使其类似于模型(空白+ Word(Textbox3)+ Space + Word(Textbox4)+ Space + Word(Textbox5)+ Space + Word (Textbox6)这是要如何保存项目的屏幕快照。不幸的是,起初我对空白处的感觉不太好。

IMG3

IMG4

 Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = System.IO.File.ReadAllText(My.Application.Info.DirectoryPath + ("\Data\Question.dat"))
        TextBox2.Text = System.IO.File.ReadAllText(My.Application.Info.DirectoryPath + ("\Data\Answer.dat"))
    End Sub
End Class

那么,如何在文本框的新行中保存问题和答案(保存到我的文本文件中)?按照给出的例子吗?

1 个答案:

答案 0 :(得分:0)

下面的代码将使行在随机混洗中保持同步。如果您不想重复行,则必须对代码进行验证,以淘汰已经发生的绘制。

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim text1 As String
        Dim text2 As String
        Dim textarray1 As New ArrayList
        Dim textarray2 As New ArrayList
        Dim NextMember As String = ""
        Dim Rand As New Random
        Dim RandNum As Integer = 0
        TextBox1.Clear()
        TextBox2.Clear()


        text1 = "one" & vbCrLf & "two" & vbCrLf & "three" & vbCrLf
        text2 = "A" & vbCrLf & "B" & vbCrLf & "C" & vbCrLf

        For i = 1 To Len(text1)
            Do Until Mid(text1, i, 1) = vbCr
                NextMember = NextMember & Mid(text1, i, 1)
                i = i + 1
            Loop

            textarray1.Add(NextMember)
            i = i + 1
            NextMember = ""
        Next

        For i = 1 To Len(text2)
            Do Until Mid(text2, i, 1) = vbCr
                NextMember = NextMember & Mid(text2, i, 1)
                i = i + 1
            Loop

            textarray2.Add(NextMember)
            i = i + 1
            NextMember = ""
        Next


        For i = 0 To textarray1.Count - 1
            RandNum = Rand.Next(textarray1.Count)
            TextBox1.Text = TextBox1.Text & textarray1(RandNum) & vbCrLf
            TextBox2.Text = TextBox2.Text & textarray2(RandNum) & vbCrLf
        Next



    End Sub