claudebl
claudebl

Reputation: 75

How to check instantly the changes made by user in TextBoxs?

The procedure allows the modification of text zones by means of an Modify button on the main form. Using a structure, I read and store lines from a text file, and populated according to line number, 3 text boxes. On the other hand, in order to leave it to the user to modify something in these zones if necessary, I would need to know which text zones have been modified! Claude. Here is my code:

 Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click

        ' Modifier

        Dim bibliotheque As New article

        With bibliotheque
            .Title = TextBox1.Text
            .Name = TextBox2.Text
            .Charge = TextBox3.Text
        End With

        Dim fileName As String = "c:\essai.librairie"
        Dim someString As String = Trim(TextBox2.Text)
        Dim lignes As String() = File.ReadAllLines(fileName, Encoding.UTF8)
        Dim found As Integer = -1

        For i As Integer = 0 To lignes.Length - 1
            If lignes(i).Contains(someString) Then
                found = i
                Exit For
            End If
        Next

        Dim lines As String() = File.ReadAllLines("c:\essai.librairie", Encoding.UTF8)
        lines(found) = bibliotheque.Title.PadRight(17, " "c).ToString & bibliotheque.Name.PadRight(90, " "c).ToString & bibliotheque.Charge.PadRight(120, " "c).ToString

        MessageBox.Show("Enregistrer les données modifiées ?",
         "Prénommer", MessageBoxButtons.OKCancel,
             MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
            If Windows.Forms.DialogResult.OK Then
                File.WriteAllLines("c:\essai.librairie", lines, Encoding.UTF8)
                Using fStream As New FileStream("c:\essai.librairie", FileMode.Open, FileAccess.ReadWrite, FileShare.None)
                    fStream.SetLength(fStream.Length - Environment.NewLine.Length)
                End Using
            Else
                Exit Sub
            End If

    End Sub

Upvotes: 0

Views: 101

Answers (1)

xpda
xpda

Reputation: 15813

You can use the events txtbox1.changed or txtbox1.leave to take action or flag that textbox as being changed. The .changed event fires every time a character is changed. .leave only fires when focus leaves the text box.

Upvotes: 1

Related Questions