Re: Handle Worked - can someone please double check



I never knew you could put "custom properties" into vb.net forms designer.
I really like that option.

I will try that tonight once I get home from work.
I might be responding here, if I get stuck and might need a little help.
All depends on what google returns.

I have read up on the MyBase stuff but that still confuses me a bit. I'll
let that sink in - in a couple days and retry
to read that up.

Thank you.

Miro


"jeff" <jhersey at allnorth dottt com> wrote in message
news:uBuVitv4GHA.1012@xxxxxxxxxxxxxxxxxxxxxxx

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





.



Relevant Pages

  • Re: Handle Worked - can someone please double check
    ... change the behavior of the trim ... ... Public Class myTextBox ... Protected Overrides Sub OnLeave ... Private _TrimText As Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Handle Worked - can someone please double check
    ... Public Class myTextBox ... Protected Overrides Sub OnLeave ... Private _TrimText As Boolean ... Inheritance is your friend in this case. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Handle Worked - can someone please double check
    ... All examples show how to make a brand new custom control. ... to get the _TrimText property somehow. ... you can drop the myTextBox on the form ... ... Protected Overrides Sub OnLeave ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Handle Worked - can someone please double check
    ... All examples show how to make a brand new custom control. ... you can drop the myTextBox on the form ... ... Protected Overrides Sub OnLeave ... the TrimText is now a property, set it, have it - done. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Windows Media Encoder in VB -- stopped working
    ... Can you still trim the filethat you were able to ... > creating the sample files without raising any errors. ... > Dim WithEvents BasicEdit As WMEncBasicEdit ... > Sub TrimSampleFile ...
    (microsoft.public.windowsmedia.encoder)