Re: Handle Worked - can someone please double check
- From: "jeff" <jhersey at allnorth dottt com>
- Date: Thu, 28 Sep 2006 05:41:07 -0700
And another path to rome ...
If you want to reproduce this functionality on other forms ... ie. trim text
in text boxes ... you will need to duplicate this code on each form.
cut/paste/find and replace.
For reuseability ... create your own class - myTextBox - that inherits from
the base class - Windows.Forms.TextBox ... and override / extend the leave
event.
This way, you can drop the myTextBox on the form ... you are off to the
races ... no need to code anything on the form ... and if you ever need to
change the behavior of the trim ... you change it in one place ... done.
---------------------------------------------
Imports System.Windows.Forms
Namespace myControls
Public Class myTextBox
Inherits System.Windows.Forms.TextBox
Protected Overrides Sub OnLeave(ByVal e As System.EventArgs)
MyBase.OnLeave(e)
Me.Text = Trim(Me.Text)
End Sub
End Class
End Namespace
---------------------------------------------
Now, if you want to extend this a little further ... you could include a
property ... _TrimText ... set this in the designer whenever you want to
trim the spaces... This way you can always use the myTextBox control, and
set the property accordingly. Reason, if you add a text control to a
form...do your stuff with it ... coding, setting properties and so on ...
then realize you need to 'trim the text' ... you do not have to delete the
control, add your myTextBox, code it ... configure it ... again. If you
used your base control - myTextBox - from the begining, the TrimText is now
a property, set it, have it - done.
-------------------------------------
Namespace GlobalContainer
Imports System.Windows.Forms
Public Class myTextBox
Inherits System.Windows.Forms.TextBox
Private _TrimText As Boolean
<System.ComponentModel.Description("Do you want to trim the
textbox."),
System.ComponentModel.Category("Behavior")> _
Public Property TrimText() As Boolean
Get
Return _TrimText
End Get
Set(ByVal value As Boolean)
_TrimText = value
End Set
End Property
Protected Overrides Sub OnLeave(ByVal e As System.EventArgs)
MyBase.OnLeave(e)
If TrimText Then
Call ueTrimText()
End If
End Sub
Public Sub ueTrimText()
Me.Text = Trim(Me.Text)
End Sub
End Class
End Namespace
-----------------------------------------
Inheritance is your friend in this case.
Jeff.
"Miro" <mironagy@xxxxxxxxxx> wrote in message
news:O5PXy8q4GHA.3964@xxxxxxxxxxxxxxxxxxxxxxx
I wanted certain text boxes ( only certain ones ) to always be Trim'd so
that spaces are not in the begining,
nor the end of the text entered.
I created my own "Handle ?" - i hope thats the right terminology,
and it works. Is this the right way to do this?
I had to use DirectCast to get the textbox name.
Private Sub TrimValues(ByVal sender As System.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
Thanks,
Miro
.
- Follow-Ups:
- References:
- Prev by Date: Re: Looking for a real working transparent picturebox
- Next by Date: Re: Report Layout
- Previous by thread: Solved - Re: Handle Worked - can someone please double check
- Next by thread: Re: Handle Worked - can someone please double check
- Index(es):
Relevant Pages
|
Loading