views:

227

answers:

2

Hi,

I want to let TextBox control TextChanged event fire only when there are more than one character in the TextBox.

Thank you.

A: 

I think you'll need a custom control that inherits the textbox control with a custom event, do your checks at the internal event, and fire your custom event when you see appropriate.

Basel Nimer
A: 
Public Class ZTextBox
Inherits System.Windows.Forms.TextBox
Public Event ZTextChanged(ByVal sender As Object, ByVal e As System.EventArgs)

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    MyBase.OnPaint(e)

    'Add your custom paint code here
End Sub

Private Sub ZTextBox_TextChanged1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.TextChanged
    If Me.Text.Length > 3 Then
        RaiseEvent ZTextChanged(sender, e)
    End If
End Sub End Class

and you can use the following in your form

    Private Sub ZTextBox1_ZTextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ZTextBox1.ZTextChanged
    MsgBox(1)
End Sub
Basel Nimer