Question

I have tried using IsNumeric() but it does not fulfill what I want to achieve.

I have a MaskedTextBox. 4-digits and - as PromptChar.

enter image description here

What I want is to trigger an event checkSomething() when there is 4-digit combination.

Say, 0001 then it will get an event. But nothing will happen when there is still a - in it. (000- | -001 and so on)

If mtPig.Text has 4digits then
.....
Else
Was it helpful?

Solution

Private Function IsTextInteger(target As TextBox) As Boolean

    If Integer.TryParse(target.Text, Nothing) Then            
        If target.Text.Length = 4 Then Return True
    Else
        Return False
    End If
End Function

OTHER TIPS

Look at the MaskCompleted (http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.maskcompleted.aspx) and MaskFull properties.

MaskCompleted - all mandatory characters have been entered

MaskFull - all mandatory and optional characters have been entered

You could use the Validating event as @Vignesh has, or KeyPress if you want to do it keystroke by keystroke.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top