Re: Handle Worked - can someone please double check
- From: "Phill W." <p-.-a-.-w-a-r-d@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 28 Sep 2006 14:33:03 +0100
Miro wrote:
Is this the right way to do this?.. . .
Private Sub TrimValues(ByVal sender As Object, ByVal e As EventArgs) _
Handles txtOne.Leave, txtTwo.Leave, txtThree.Leave, txtFour.Leave, _
txtFive.Leave, txtSix.Leave, txtSeven.Leave
DirectCast(sender, TextBox).Text _ = Trim(DirectCast(sender, TextBox).Text)
End Sub
That'll do nicely, with just one suggestion:
DirectCast(sender, TextBox).Text _
= Trim(DirectCast(sender, TextBox).Text)
might be clearer as
With DirectCast(sender, TextBox)
.Text = .Text.Trim()
End With
Or, you could go further still and make a custom TextBox class, inherited from TextBox and build this code into an Override for the OnLeave method. That way, you can reuse it in as many Forms/applications as you like - something like
Class TrimmedTextBox
Inherits TextBox
Public Sub New()
MyBase.New()
End Sub
Protected Overrides Sub OnLeave()
' Raise the "Leave" Event
MyBase.OnLeave()
' Force the Text to be trimmed
Me.Text = Me.Text.Trim()
End Sub
End Class
Then replace the TextBox declarations in the "Generated Code" .. er .. code with your custom class.
Replace
Friend WithEvents txtOne As ...TextBox
. . .
txtOne = New ...TextBox
with
Friend WithEvents txtOne As TrimmedTextBox
. . .
txtOne = New TrimmedTextBox
HTH,
Phill W.
.
- References:
- Prev by Date: Re: How to find the position of the first dash in a string
- Next by Date: Iterate a structure to get name and value
- Previous by thread: Re: Handle Worked - can someone please double check
- Next by thread: Re: filter dataTable/datagridview to show top 1 row for duplicate IDs?
- Index(es):
Relevant Pages
|