We help IT Professionals succeed at work.

how to add my own custom property in textbox class in vb.net windows application?

how to add my own custom property in textbox class in vb.net windows application?
if I define any of Object for that textbox, that my custom property should appear.

for example (my own custom property )
 
Public Class welcome
    Dim m As String
    Public Property calculate()
        Get
            calculate = m
        End Get
        Set(ByVal value)
            m = value
        End Set
    End Property
End Class

above is my own custom property.
I want to do  following aim


dim  a as system.windows.forms.textbox  
dim b as system.windows.forms.textbox
a.calculate="hellow"
b.calculate="hai"
msgbox (a.calculate)
msgbox (b.calculate)

what are the ways available for my purpose ?
is it possible ?
can i do anything like textbox class is base and welcome class is derive ?
Comment
Watch Question

Éric MoreauSenior .Net Consultant
Top Expert 2016
Commented:

Author

Commented:
without using user control ,
can  not we create into windows form application ?
 
Éric MoreauSenior .Net Consultant
Top Expert 2016
Commented:
yes you have to create a class that inherits from the textbox to which you add your own properties and methods and then you can use this new class.

you don't absolutely need to create a DLL from it (it just ease reuse between projects)
Most Valuable Expert 2012
Top Expert 2014

Commented:
What's the actual purpose? If you just want to store some value then look into the Tag property of Textbox (its on almost all controls) which is of type Object so you can store anything.

Author

Commented:

super mister expert "codecruiser". I know  about tag property and  I have used the tag property in   all my  project. I want to add more than 10 to 20 properties like tag property  or writing property procedure .  my application development has the controls (textbox, listbox, combobox , flexgrid, etc ).  in my few applications.  I want to add 10 properties with input controls in few  application developing. I want to add 15 properties with few input controls in few application developing  according my application development.
how to do it  ?
       
Most Valuable Expert 2012
Top Expert 2014
Commented:
You still have two options

1) Extend all of these controls and add the properties/methods. Then use these extended controls in all your projects.

2) Use a custom class to store all the properties/methods that you want and then assign an object of this class to tag property of the controls.

If the code will be same for all the controls (same properties/methods), I will choose (2) because it will mean less code duplication and easy code maintenance as you have a single class to change.
Éric MoreauSenior .Net Consultant
Top Expert 2016
Commented:
>>how to do it  ?

inherits from the control as I have shown in my article
Here's a partial solution of your problem that does not require creating inherited object. If you are going to only get your property, here's what you can do:

Imports System.Runtime.CompilerServices
Module Module1
    <Extension()> _
    Public Function USText(Byval txt As System.Windows.Forms.TextBox)
        Return IIf(txt.text = string.empty, "US", txt.text)
    End Function
End Module

With that, new property "ustext" will become available for the textbox:

msgbox textbox1.ustext

will show "US" is the textbox is empty.


(I found this old question while researching the same question)