PC Review


Reply
Thread Tools Rate Thread

amend a control by function or class

 
 
Benson Wong
Guest
Posts: n/a
 
      31st Jan 2007
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.


 
Reply With Quote
 
 
 
 
lord.zoltar@gmail.com
Guest
Posts: n/a
 
      31st Jan 2007
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

 
Reply With Quote
 
Phill W.
Guest
Posts: n/a
 
      31st Jan 2007
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.
 
Reply With Quote
 
Benson
Guest
Posts: n/a
 
      1st Feb 2007
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>
???????:epqdvs$ekf$(E-Mail Removed)...
> 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.



 
Reply With Quote
 
lord.zoltar@gmail.com
Guest
Posts: n/a
 
      1st Feb 2007
On Jan 31, 7:46 pm, "Benson" <benson...@yahoo.com.hk> wrote:
> 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).

 
Reply With Quote
 
Branco Medeiros
Guest
Posts: n/a
 
      1st Feb 2007
lord.zol wrote:
> On Jan 31, 7:46 pm, "Benson" <benson...@yahoo.com.hk> wrote:

<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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insufficient pemissions to amend Excel files but can amend Word fi =?Utf-8?B?RiBMYXVmcw==?= Microsoft Windows 2000 Security 0 11th Oct 2006 12:28 PM
Calling a class function from another class =?Utf-8?B?TWFjY2E=?= Microsoft C# .NET 2 13th Mar 2006 12:46 PM
How to control access to inner class through outer class =?Utf-8?B?TWFyaXVzSQ==?= Microsoft Dot NET 9 2nd Mar 2006 04:37 PM
Problem Passing control as a param into a class function =?Utf-8?B?R3Jvc2No?= Microsoft C# .NET 2 1st Feb 2005 02:29 AM
How to Create a Function Point for a class member function. Microsoft Microsoft VC .NET 2 13th Aug 2004 09:00 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:21 AM.