Occurs before a text typed or pasted by the user is parsed.
Class: SftDate
Namespace: Softelvdm.SftDateNET
Assembly: Softelvdm.SftDateNET
public event TextParsingEventHandler TextParsing;
Public Event TextParsing As TextParsingEventHandlerOccurs before a text typed or pasted by the user is parsed.
private void sftDate2_TextParsing(object sender, TextParsingEventArgs e) {
Match m = Regex.Match(e.Text.Trim(), @"^([+-])\s*(\d{1,4})$");
if (m.Success) {
int days = int.Parse(m.Groups[2].Value);
e.Value = DateTime.Today.AddDays(m.Groups[1].Value == "-" ? -days : days);
e.Handled = true;
}
DumpValues("sftDate2.TextParsing", e);
}
private void sftDate2_ValueValidating(object sender, ValueValidatingEventArgs e) {
DumpValues("sftDate2.ValueValidating", e);
}
private void sftDate2_ValueChanged(object sender, EventArgs e) {
DumpValues("sftDate2.ValueChanged (" + sftDate2.Text + ")", e);
End Sub
Private Sub SftDate1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles SftDate1.KeyDown
DumpValues("SftDate1.KeyDown", e)
End Sub
' SftDate2 - a free-form field; besides dates in the culture's format it accepts +n and -n days from today
Private Sub SftDate2_TextParsing(ByVal sender As Object, ByVal e As TextParsingEventArgs) Handles SftDate2.TextParsing
Dim m As Match = Regex.Match(e.Text.Trim(), "^([+-])\s*(\d{1,4})$")
If m.Success Then
Dim days As Integer = Integer.Parse(m.Groups(2).Value)
e.Value = DateTime.Today.AddDays(If(m.Groups(1).Value = "-", -days, days))
e.Handled = True
End If
DumpValues("SftDate2.TextParsing", e)See Also SftDate Class | Classes | SftDate/NET 3.0