amend a control by function or class

  • Thread starter Thread starter Benson Wong
  • Start date Start date
B

Benson Wong

I want to write a tailor-made function or class to amend textedit controls,
so that their properties are consistent or changed by some rules.
My idea is as follows:
TailorMadeRoutine(TextBox1)

sub TailorMadeRoutine(object textbox)
textbox.color=...
textbox.size=...
end

Is this idea works?
Benson
VB2005.
 
I want to write a tailor-made function or class to amend textedit controls,
so that their properties are consistent or changed by some rules.
My idea is as follows:
TailorMadeRoutine(TextBox1)

sub TailorMadeRoutine(object textbox)
textbox.color=...
textbox.size=...
end

Is this idea works?
Benson
VB2005.

VB .NET allows for inheritance. The way I would do this is to create a
new textEdit control that inherits the original one:

Public Class MyCustomTextControl
inherits Windows.Forms.TextEdit '...or whatever control you want
to extend the functionality of...

Public Sub MyCustomeProcedure
Me.color = ...
Me.text = ....
End sub
End Class
 
Benson said:
I want to write a tailor-made function or class to amend textedit controls,
so that their properties are consistent or changed by some rules.

Inherit a class of your own from TextBox and customise to your heart's
content.

When dealing with events in your class, extend the On* routines rather
than attaching event handlers, something like

Protected Overrides Sub OnLeave(ByVal e as EventArgs)
' Do the custom thing
Me.BackColor = Color.Green

' Get the TextBox to raise the Leave event
MyBase.OnLeave(e)

End Sub

HTH,
Phill W.
 
Thanks.
Further Question:
Can I do the inheritance as follows?
1. Inherit TextBox
2. Create a new property ID
3. code the SETID procedure like this:
if ID="CUSTOMER" then
get database content
if something then .backcolor=color.green
if ...
end if
4. Will this new control appear on the toolsbox, so that I can drag it on
the form?

Thanks.
Benson.
 
Thanks.
Further Question:
Can I do the inheritance as follows?
1. Inherit TextBox
2. Create a new property ID
3. code the SETID procedure like this:
if ID="CUSTOMER" then
get database content
if something then .backcolor=color.green
if ...
end if
4. Will this new control appear on the toolsbox, so that I can drag it on
the form?


It should appear on the toolbox after you compile the files. If you
add any new properties to the inherited TextBox, you should see them
in the Properties panel in the design-view When you are adding your
new control to other controls or forms (Except for private or
writeonly properties, I think).
 
lord.zol said:
On Jan 31, 7:46 pm, "Benson" <[email protected]> wrote:

It should appear on the toolbox after you compile the files.
<snip>

Actually, the control will appear in the tool box after you perform a
build (no need of a full compile).

HTH.
Regards,

Branco.
 
Back
Top