473,385 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Handle Worked - can someone please double check

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
Sep 28 '06 #1
10 1543
Miro,

Using VB.Net, there are more roads that leads to Rome, but there is in my
idea nothing wrong with your solution.

You can use as well a kind of generic setting of the handle in by instance
the load form event

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doset(Me)
End Sub
Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
if TypeOf ctr Is Textbox then
AddHandler ctr.LostFocus, AddressOf TrimValues
doSet(ctr)
Next
End Sub
////

And then your procedure.

This is a recursive method, because the textboxes in by instance a groupbox
have to be handled as well.

I hope this helps a little bit?

Cor

"Miro" <mi******@golden.netschreef in bericht
news:O5**************@TK2MSFTNGP04.phx.gbl...
>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

Sep 28 '06 #2
It does,
1. That the first is ok
2. That I can go thru what you have given me as the second option.

Slowely this vb stuff is starting ot make sence :)

Thank you very much for the help!!
I appreciate it.

Miro

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:uT*************@TK2MSFTNGP06.phx.gbl...
Miro,

Using VB.Net, there are more roads that leads to Rome, but there is in my
idea nothing wrong with your solution.

You can use as well a kind of generic setting of the handle in by instance
the load form event

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doset(Me)
End Sub
Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
if TypeOf ctr Is Textbox then
AddHandler ctr.LostFocus, AddressOf TrimValues
doSet(ctr)
Next
End Sub
////

And then your procedure.

This is a recursive method, because the textboxes in by instance a
groupbox have to be handled as well.

I hope this helps a little bit?

Cor

"Miro" <mi******@golden.netschreef in bericht
news:O5**************@TK2MSFTNGP04.phx.gbl...
>>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


Sep 28 '06 #3

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" <mi******@golden.netwrote in message
news:O5**************@TK2MSFTNGP04.phx.gbl...
>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

Sep 28 '06 #4
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.
Sep 28 '06 #5
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 comwrote in message
news:uB**************@TK2MSFTNGP05.phx.gbl...
>
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" <mi******@golden.netwrote in message
news:O5**************@TK2MSFTNGP04.phx.gbl...
>>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


Sep 28 '06 #6

all the myBase does ... is ensure the ancestor's event is called ... before
your override is called...

look at inheritance.

Jeff.
"Miro" <mi******@golden.netwrote in message
news:OF*************@TK2MSFTNGP02.phx.gbl...
>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 comwrote in message
news:uB**************@TK2MSFTNGP05.phx.gbl...
>>
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" <mi******@golden.netwrote in message
news:O5**************@TK2MSFTNGP04.phx.gbl...
>>>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



Sep 28 '06 #7
Jeff,

Im a bit stumped. - I was wondering if you can help me out just a bit
further. Im on the edge of the cliff, I just need
a bit more of a push. :)
Ive never done anything like this before so I may be just searching for the
wrong thing in help.

The closest I have found a walkthru on how to do this is in the msdn

Walkthrough: Authoring a User Control with Visual Basic .NET
ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbconWalkthroughCreatingCompositeWFCControl.htm

All examples show how to make a brand new custom control. Is that what your
example shows?
I understood your example as the TextBox given by the forms designer was to
get the _TrimText property somehow.

I took the code you supplied and made a new module / .vb or whatever it is
that it is called, and added that to my project.
I did have to change one thing in your code, I had to move this " Imports
System.Windows.Forms " before the namespace command. It didnt like it
after,

But I cant figure out what to do with this now. How do I get the custom
property to show up in the windows form designer.

Ive googled as well, and in that case all I found was an example like this:
http://www.codeproject.com/cs/combob...terchecked.asp
http://www.learn247.net/weRock247/la.../section_4.htm
but i dont think thats what im looking for either.

I think i just need a walkthru or something of this one example linke or
something and then I can go on creating custom controls everywhere :)

Cause if this works - which what you did is open a whole new world, as I
understand it, Instead of having a command button that has an Icon on it,
and coding everywhere the OnEnter, OnLeave and OnClick to change the ICON
picture, I can create 3 additional properties that hold pictures / icons and
then write a handler to reference those, instead of having the same /
simillar code written over and over again changing the icon everywhere. -
But thats another newsgroup question - if and when i get stuck on that. :)

Thank you for your time so far.

Miro
"jeff" <jhersey at allnorth dottt comwrote in message
news:uX**************@TK2MSFTNGP03.phx.gbl...
>
all the myBase does ... is ensure the ancestor's event is called ...
before your override is called...

look at inheritance.

Jeff.
"Miro" <mi******@golden.netwrote in message
news:OF*************@TK2MSFTNGP02.phx.gbl...
>>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 comwrote in message
news:uB**************@TK2MSFTNGP05.phx.gbl...
>>>
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" <mi******@golden.netwrote in message
news:O5**************@TK2MSFTNGP04.phx.gbl...
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



Sep 30 '06 #8
I think I got it Jeff.

Here is what I had to do. I was using a vb.net ( pre 2003 ) version.
Old company I worked for gave it to me as a parting gift cause they dropped
it.
But for what I am learning, I uninstalled it, and downloaded vb.net 2005
express and now I see the
"myTextBox" in my own components toolbar.

If i put it on a form I can see the Trim Text property there. The icon on
the text box looks like a gear.

Im assuming this is what you had in mind?

Miro


"Miro" <mi******@golden.netwrote in message
news:uo**************@TK2MSFTNGP03.phx.gbl...
Jeff,

Im a bit stumped. - I was wondering if you can help me out just a bit
further. Im on the edge of the cliff, I just need
a bit more of a push. :)
Ive never done anything like this before so I may be just searching for
the wrong thing in help.

The closest I have found a walkthru on how to do this is in the msdn

Walkthrough: Authoring a User Control with Visual Basic .NET
ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbconWalkthroughCreatingCompositeWFCControl.htm

All examples show how to make a brand new custom control. Is that what
your example shows?
I understood your example as the TextBox given by the forms designer was
to get the _TrimText property somehow.

I took the code you supplied and made a new module / .vb or whatever it is
that it is called, and added that to my project.
I did have to change one thing in your code, I had to move this " Imports
System.Windows.Forms " before the namespace command. It didnt like it
after,

But I cant figure out what to do with this now. How do I get the custom
property to show up in the windows form designer.

Ive googled as well, and in that case all I found was an example like
this:
http://www.codeproject.com/cs/combob...terchecked.asp
http://www.learn247.net/weRock247/la.../section_4.htm
but i dont think thats what im looking for either.

I think i just need a walkthru or something of this one example linke or
something and then I can go on creating custom controls everywhere :)

Cause if this works - which what you did is open a whole new world, as I
understand it, Instead of having a command button that has an Icon on it,
and coding everywhere the OnEnter, OnLeave and OnClick to change the ICON
picture, I can create 3 additional properties that hold pictures / icons
and then write a handler to reference those, instead of having the same /
simillar code written over and over again changing the icon everywhere. -
But thats another newsgroup question - if and when i get stuck on that. :)

Thank you for your time so far.

Miro
"jeff" <jhersey at allnorth dottt comwrote in message
news:uX**************@TK2MSFTNGP03.phx.gbl...
>>
all the myBase does ... is ensure the ancestor's event is called ...
before your override is called...

look at inheritance.

Jeff.
"Miro" <mi******@golden.netwrote in message
news:OF*************@TK2MSFTNGP02.phx.gbl...
>>>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 comwrote in message
news:uB**************@TK2MSFTNGP05.phx.gbl...

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" <mi******@golden.netwrote in message
news:O5**************@TK2MSFTNGP04.phx.gbl...
>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
>




Oct 1 '06 #9

yup.

That is what I expected ... Sorry, I am new to VB and VB.Net (just started
using it about 6 months ago) and I am not sure what is specific to VS 2005.
That is all I have ... never used other versions.

As you can see, the custom class (user control) will appear in your toolbox
and from there, you can drag and drop it on to other controls.

As for you next question ... button with picture box ... yes this is a
perfect example for using inheritance ...

Lets says you have two types of buttons you want to do this (onLever ,
onEnter, onClick) with ... an OK button and a CANCEL button.

First,
1. Create a base myCommandButton ... inherited from CommandButtons.
2. Create the necessary properties ... icon file or whatever ...
3. Code / Extend the events accordingly ... on enter ... on leave ... on
click ...

Create a new class myOKButton ... that inhertis from myCommandButton

1. Set it's custom ICON properties to what you want for OK buttons.
2. Now, when you want to use an OK button ... you are done. Drag it, drop
it on to your other controls.
3. You do not need to worry about setting its custom properties ...
4. Now if you ever want to change the settings for you OK button throughout
your application, you change your 'myOKButton' ...done.

Create a new class myCANCELButton ... that inherits from myCommandButton ...

1. repeat process ...

Hope this helps ...

Jeff.
"Miro" <mi******@golden.netwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>I think I got it Jeff.

Here is what I had to do. I was using a vb.net ( pre 2003 ) version.
Old company I worked for gave it to me as a parting gift cause they
dropped it.
But for what I am learning, I uninstalled it, and downloaded vb.net 2005
express and now I see the
"myTextBox" in my own components toolbar.

If i put it on a form I can see the Trim Text property there. The icon on
the text box looks like a gear.

Im assuming this is what you had in mind?

Miro


"Miro" <mi******@golden.netwrote in message
news:uo**************@TK2MSFTNGP03.phx.gbl...
>Jeff,

Im a bit stumped. - I was wondering if you can help me out just a bit
further. Im on the edge of the cliff, I just need
a bit more of a push. :)
Ive never done anything like this before so I may be just searching for
the wrong thing in help.

The closest I have found a walkthru on how to do this is in the msdn

Walkthrough: Authoring a User Control with Visual Basic .NET
ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbconWalkthroughCreatingCompositeWFCControl.htm

All examples show how to make a brand new custom control. Is that what
your example shows?
I understood your example as the TextBox given by the forms designer was
to get the _TrimText property somehow.

I took the code you supplied and made a new module / .vb or whatever it
is that it is called, and added that to my project.
I did have to change one thing in your code, I had to move this "
Imports System.Windows.Forms " before the namespace command. It didnt
like it after,

But I cant figure out what to do with this now. How do I get the custom
property to show up in the windows form designer.

Ive googled as well, and in that case all I found was an example like
this:
http://www.codeproject.com/cs/combob...terchecked.asp
http://www.learn247.net/weRock247/la.../section_4.htm
but i dont think thats what im looking for either.

I think i just need a walkthru or something of this one example linke or
something and then I can go on creating custom controls everywhere :)

Cause if this works - which what you did is open a whole new world, as I
understand it, Instead of having a command button that has an Icon on it,
and coding everywhere the OnEnter, OnLeave and OnClick to change the ICON
picture, I can create 3 additional properties that hold pictures / icons
and then write a handler to reference those, instead of having the same /
simillar code written over and over again changing the icon
verywhere. - But thats another newsgroup question - if and when i get
stuck on that. :)

Thank you for your time so far.

Miro
"jeff" <jhersey at allnorth dottt comwrote in message
news:uX**************@TK2MSFTNGP03.phx.gbl...
>>>
all the myBase does ... is ensure the ancestor's event is called ...
before your override is called...

look at inheritance.

Jeff.
"Miro" <mi******@golden.netwrote in message
news:OF*************@TK2MSFTNGP02.phx.gbl...
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 comwrote in message
news:uB**************@TK2MSFTNGP05.phx.gbl...
>
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" <mi******@golden.netwrote in message
news:O5**************@TK2MSFTNGP04.phx.gbl.. .
>>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
>>
>
>




Oct 2 '06 #10
It does help greatly.

Im new to vb as well, and I am glad I updated to the 2005 ver. Even if it
is express. It is way better, and handles some objects better. Plus now
when I go search on google, I know everything will work.

Thank you for all your help.

Two last quick questions.
1. In the code - where you define the "Namespace" . Is there a list of
"reserved" namespaces or can I choose any word I want for a namespace.

2. I am supposing I should keep the myTrimText.vb file with the property
setting on 'Compile' ?

Ive been searching google with "inheritance" but things come up that I'm not
really looking for.

Thank you again for all ur help.

Miro

"jeff" <jhersey at allnorth dottt comwrote in message
news:eX**************@TK2MSFTNGP03.phx.gbl...
>
yup.

That is what I expected ... Sorry, I am new to VB and VB.Net (just started
using it about 6 months ago) and I am not sure what is specific to VS
2005. That is all I have ... never used other versions.

As you can see, the custom class (user control) will appear in your
toolbox and from there, you can drag and drop it on to other controls.

As for you next question ... button with picture box ... yes this is a
perfect example for using inheritance ...

Lets says you have two types of buttons you want to do this (onLever ,
onEnter, onClick) with ... an OK button and a CANCEL button.

First,
1. Create a base myCommandButton ... inherited from CommandButtons.
2. Create the necessary properties ... icon file or whatever ...
3. Code / Extend the events accordingly ... on enter ... on leave ... on
click ...

Create a new class myOKButton ... that inhertis from myCommandButton

1. Set it's custom ICON properties to what you want for OK buttons.
2. Now, when you want to use an OK button ... you are done. Drag it, drop
it on to your other controls.
3. You do not need to worry about setting its custom properties ...
4. Now if you ever want to change the settings for you OK button
throughout your application, you change your 'myOKButton' ...done.

Create a new class myCANCELButton ... that inherits from myCommandButton
...

1. repeat process ...

Hope this helps ...

Jeff.
"Miro" <mi******@golden.netwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>>I think I got it Jeff.

Here is what I had to do. I was using a vb.net ( pre 2003 ) version.
Old company I worked for gave it to me as a parting gift cause they
dropped it.
But for what I am learning, I uninstalled it, and downloaded vb.net 2005
express and now I see the
"myTextBox" in my own components toolbar.

If i put it on a form I can see the Trim Text property there. The icon
on the text box looks like a gear.

Im assuming this is what you had in mind?

Miro


"Miro" <mi******@golden.netwrote in message
news:uo**************@TK2MSFTNGP03.phx.gbl...
>>Jeff,

Im a bit stumped. - I was wondering if you can help me out just a bit
further. Im on the edge of the cliff, I just need
a bit more of a push. :)
Ive never done anything like this before so I may be just searching for
the wrong thing in help.

The closest I have found a walkthru on how to do this is in the msdn

Walkthrough: Authoring a User Control with Visual Basic .NET
ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbconWalkthroughCreatingCompositeWFCControl.htm

All examples show how to make a brand new custom control. Is that what
your example shows?
I understood your example as the TextBox given by the forms designer was
to get the _TrimText property somehow.

I took the code you supplied and made a new module / .vb or whatever it
is that it is called, and added that to my project.
I did have to change one thing in your code, I had to move this "
Imports System.Windows.Forms " before the namespace command. It didnt
like it after,

But I cant figure out what to do with this now. How do I get the custom
property to show up in the windows form designer.

Ive googled as well, and in that case all I found was an example like
this:
http://www.codeproject.com/cs/combob...terchecked.asp
http://www.learn247.net/weRock247/la.../section_4.htm
but i dont think thats what im looking for either.

I think i just need a walkthru or something of this one example linke or
something and then I can go on creating custom controls everywhere :)

Cause if this works - which what you did is open a whole new world, as I
understand it, Instead of having a command button that has an Icon on
it, and coding everywhere the OnEnter, OnLeave and OnClick to change the
ICON picture, I can create 3 additional properties that hold pictures /
icons and then write a handler to reference those, instead of having the
same / simillar code written over and over again changing the icon
verywhere. - But thats another newsgroup question - if and when i get
stuck on that. :)

Thank you for your time so far.

Miro
"jeff" <jhersey at allnorth dottt comwrote in message
news:uX**************@TK2MSFTNGP03.phx.gbl...

all the myBase does ... is ensure the ancestor's event is called ...
before your override is called...

look at inheritance.

Jeff.
"Miro" <mi******@golden.netwrote in message
news:OF*************@TK2MSFTNGP02.phx.gbl...
>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 comwrote in message
news:uB**************@TK2MSFTNGP05.phx.gbl.. .
>>
>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" <mi******@golden.netwrote in message
>news:O5**************@TK2MSFTNGP04.phx.gbl. ..
>>>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
>>>
>>
>>
>
>




Oct 2 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Randy | last post by:
Hello All, I'm trying to discover the best way to handle the situation where you have a datagrid in your app and someone changes a cell but doesn't leave that cell (so there's the little pencil...
2
by: Boni | last post by:
Dear all, I am interested in mouse down and double click events of a control. When doubleclick happens the processing for mouse down should't be done I did follwing: sub MyMouseDown(.) handles...
0
by: Ian Harding | last post by:
Today, for no obvious reason, I started getting this error when attempting to create an instance of a COM+ hosted component (C++/ATL COM) from my .NET Serviced component (both hosted in the same...
4
by: Jack | last post by:
Hi, I have a asp page where part of the code is as follows. This builds up the sql statement partially. sql01 = "UPDATE EquipmentTbl SET " sql01 = sql01 & "SerialNumber = '" &...
3
by: Stefan Mueller | last post by:
I've a web page with several input boxes. After the user clicks 'submit' I insert these data into my MySQL database. This worked for several months perfect. But today a user entered the street...
1
by: ryann18 | last post by:
Can someone please help with this modifying Account problem!?!?! Modify the Account class so that it also permits an account to be opened with just a name and an account number, assuming an...
6
by: Liming | last post by:
Hi, In a typical 3 tier model (view layer, busines layer and data access layer) where do you handle your exceptions? do you let it buble up all the way to the .aspx pages or do you handle it in...
3
by: Greatness | last post by:
#include <iostream> void sizeYear(double,double,double ,int); using namespace std; int main() { double population;
3
by: ITAutobot25 | last post by:
Now this is really the last problem (for real now) with this assignment. My sorter is not working. I managed to sort by product name in my previous assignment; however, I can't get it to work on this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.