T
teddysnips
WINDOWS FORMS
I've a form that has a textbox that allows the user to enter a string.
On the LostFocus event, the textbox formats the string into a preferred
format.
However, if the user presses the "Save" button while the textbox has
the focus, the LostFocus code doesn't run at the right time, so that
the "Save" function is dealing with an incorrectly formatted string and
the whole caboodle goes splat.
I like the LostFocus event, because I've got upwards of 14 such
textboxes on various tabs on the form, which all may contain different
strings but must all be formatted in the correct format. Here is the
function that handles this:
Private Sub txtTimeStartAndEndArbitrated(ByVal sender As Object,
ByVal e As System.EventArgs) Handles txtMonStartArbitrated.LostFocus,
txtMonEndArbitrated.LostFocus, _
txtTueStartArbitrated.LostFocus, txtTueEndArbitrated.LostFocus, _
txtWedStartArbitrated.LostFocus, txtWedEndArbitrated.LostFocus, _
txtThurStartArbitrated.LostFocus, txtThurEndArbitrated.LostFocus,
_
txtFriStartArbitrated.LostFocus, txtFriEndArbitrated.LostFocus, _
txtSatStartArbitrated.LostFocus, txtSatEndArbitrated.LostFocus, _
txtSunStartArbitrated.LostFocus, txtSunEndArbitrated.LostFocus
Dim txtTextBox As TextBox = CType(sender, TextBox)
txtTextBox.Text = FormatArbTime(txtTextBox.Text)
End Sub
Any thoughts?
Edward
I've a form that has a textbox that allows the user to enter a string.
On the LostFocus event, the textbox formats the string into a preferred
format.
However, if the user presses the "Save" button while the textbox has
the focus, the LostFocus code doesn't run at the right time, so that
the "Save" function is dealing with an incorrectly formatted string and
the whole caboodle goes splat.
I like the LostFocus event, because I've got upwards of 14 such
textboxes on various tabs on the form, which all may contain different
strings but must all be formatted in the correct format. Here is the
function that handles this:
Private Sub txtTimeStartAndEndArbitrated(ByVal sender As Object,
ByVal e As System.EventArgs) Handles txtMonStartArbitrated.LostFocus,
txtMonEndArbitrated.LostFocus, _
txtTueStartArbitrated.LostFocus, txtTueEndArbitrated.LostFocus, _
txtWedStartArbitrated.LostFocus, txtWedEndArbitrated.LostFocus, _
txtThurStartArbitrated.LostFocus, txtThurEndArbitrated.LostFocus,
_
txtFriStartArbitrated.LostFocus, txtFriEndArbitrated.LostFocus, _
txtSatStartArbitrated.LostFocus, txtSatEndArbitrated.LostFocus, _
txtSunStartArbitrated.LostFocus, txtSunEndArbitrated.LostFocus
Dim txtTextBox As TextBox = CType(sender, TextBox)
txtTextBox.Text = FormatArbTime(txtTextBox.Text)
End Sub
Any thoughts?
Edward