473,320 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

amend a control by function or class

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
5 1336
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Richard Brown | last post by:
Ok, I've been looking through the .NET SDK docs and stuff. I'm wondering if you can provide a control extender that does generic validation or functionality just by dropping it on the form. For...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
1
by: GPD | last post by:
I thought I had done this before but cant see a way how. Am sure I once opened a table and amended some data. Anyone know if possible or how, any permissions needed from 10G EM. PS I know...
5
by: yusufjammy | last post by:
How to control or interface with parallel port in c++ programming .
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.