Re: Handle Worked - can someone please double check
- From: "Miro" <mironagy@xxxxxxxxxx>
- Date: Sun, 1 Oct 2006 10:28:44 -0400
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" <mironagy@xxxxxxxxxx> wrote in message
news:uoHRg7D5GHA.4064@xxxxxxxxxxxxxxxxxxxxxxx
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/combobox/betterchecked.asp
http://www.learn247.net/weRock247/labs/winforms/vb/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 com> wrote in message
news:uXGwHew4GHA.4256@xxxxxxxxxxxxxxxxxxxxxxx
all the myBase does ... is ensure the ancestor's event is called ...
before your override is called...
look at inheritance.
Jeff.
"Miro" <mironagy@xxxxxxxxxx> wrote in message
news:OFe2GXw4GHA.292@xxxxxxxxxxxxxxxxxxxxxxx
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
.
- Follow-Ups:
- References:
- Prev by Date: Can't run Web Services
- Next by Date: Re: how to get both old and new value for a changed text box
- Previous by thread: Re: Handle Worked - can someone please double check
- Next by thread: Re: Handle Worked - can someone please double check
- Index(es):