The format event is used to perform "live" formatting to a field's value as the user types into a text control.
Note: EventArgs describe the properties which can be read and/or written in order to affect the outcome of the event.
Supported By: |
|
||||
Format events are supported by Multi-line text boxes, dropdown edit boxes, and text boxes. |
|||||
|
|||||
EventArgs Properties:
|
|||||
Cancel |
Boolean |
Read/Write |
Set this property to True if you have overridden the default formatting behavior or to prevent the default formatting from occurring. |
||
Value |
String |
Read/Write |
The value to be formatted. Setting this property will cause the field’s default formatting to be applied to the new value. |
||
|
|||||
Example: |
|
|
|||
The following code demonstrates how to format a 10-digit zip code field by inserting a "-" between the 5th and 6th numbers typed. |
|||||
|
|
||||
'First we need to remove any non-numeric characters |
|||||
Dim i as Integer |
|
|
|
||
Dim Zip as String = " " |
|||||
|
|
|
|||
For i = 0 to EventArgs.Value.Length - 1 |
|||||
If Char.IsDigit (EventArgs.Value.Substring(i, 1)) Then |
|||||
Zip = Zip & EventArgs.Value.Substring(i, 1) |
|||||
End If |
|||||
Next |
|||||
|
|||||
' Handle the different formats based on the text length |
|||||
If Zip.Length <= 5 Then |
|||||
EventArgs.Value = Zip |
|||||
Else If Zip.Length <= 9 Then |
|||||
EventArgs.Value = Zip.Substring(0, 5) & "-" & Zip.Substring(5) |
|||||
Else |
|
|
|||
EventArgs.Value = Zip.Substring(0, 5) & "-" & Zip.Substring(5, 4) |
|||||
End If |