Articles in this section
Category / Section

How to dynamically validate text using the TextChanged event in the WinForms SyntaxEditor (EditControl)?

1 min read

Validation

This can be easily accomplished using the TextChanged event and a timer. The validation routine is invoked in response to a brief pause in typing by the user. Refer the below code snippets.

C#

private void editControl1_TextChanged(object sender, System.EventArgs e)
{
   // Do not start the timer as long as characters are being typed.
   if (this.timer1.Enabled == true)
   {
       this.timer1.Stop();
       this.timer1.Start();
   }
}
private void timer1_Tick(object sender, System.EventArgs e)
{
       this.ValidateText();
       this.timer1.Stop();
}
private void ValidateText()
{
       // Perform your validation logic here.
       Console.WriteLine("Text validated");
}

 

VB

Private Sub editControl1_TextChanged(sender As Object, e As System.EventArgs) Handles
editControl1.TextChanged
    ' Do not start the timer as long as characters are being typed.
    If Me.timer1.Enabled = True Then
        Me.timer1.Stop()
    End If
    Me.timer1.Start()
End Sub 'editControl1_TextChanged
Private Sub timer1_Tick(sender As Object, e As System.EventArgs) Handles timer1.Tick
    Me.ValidateText()
    Me.timer1.Stop()
End Sub 'timer1_Tick
Private Sub ValidateText()
    ' Perform your validation logic here.
    MessageBox.Show("Text validated")
End Sub 'ValidateText

 

Reference link: https://help.syncfusion.com/windowsforms/syntax-editor/events#text-events

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied