Re: Handle Worked - can someone please double check



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 com> wrote in message
news:eXFQ74h5GHA.5108@xxxxxxxxxxxxxxxxxxxxxxx

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" <mironagy@xxxxxxxxxx> wrote in message
news:%23m4KbWW5GHA.2536@xxxxxxxxxxxxxxxxxxxxxxx
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
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 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















.