By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

amend a control by function or class

P: n/a
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.
Jan 31 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Jan 31, 8:38 am, "Benson Wong" <ben...@linktechsystem.com.hk>
wrote:
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

Jan 31 '07 #2

P: n/a
Benson Wong wrote:
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.
Jan 31 '07 #3

P: n/a
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.

"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-k>
???????:ep**********@south.jnrs.ja.net...
Benson Wong wrote:
>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.

Feb 1 '07 #4

P: n/a
On Jan 31, 7:46 pm, "Benson" <benson...@yahoo.com.hkwrote:
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).

Feb 1 '07 #5

P: n/a
lord.zol wrote:
On Jan 31, 7:46 pm, "Benson" <benson...@yahoo.com.hkwrote:
<snip>
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.
<snip>

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

HTH.
Regards,

Branco.

Feb 1 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.