473,407 Members | 2,598 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,407 software developers and data experts.

Form.ControlCollection - overrideable?

Is it possible to extend the Windows.Forms.Form.ControlCollection
class and override it's Add method?

I'm adding controls to a Form and want to [automatically] hook up
Event Handling for the Form to deal with on behalf of each Control.
I /thought/ the best way to do this would be to inherit from and
override the Add method on the Form.ControlCollection class and
put some AddHandler statements in there. This much I can do but the
bit I'm missing is how to get the Form to use /my/ ControlCollection
rather than the standard one.

Any suggestions?

TIA,
Phill W.
Nov 20 '05 #1
3 2318
Phill. W schrieb:
Is it possible to extend the Windows.Forms.Form.ControlCollection
class and override it's Add method?

I'm adding controls to a Form and want to [automatically] hook up
Event Handling for the Form to deal with on behalf of each Control.
I /thought/ the best way to do this would be to inherit from and
override the Add method on the Form.ControlCollection class and
put some AddHandler statements in there. This much I can do but the
bit I'm missing is how to get the Form to use /my/ ControlCollection
rather than the standard one.


Did you see the form's 'ControlAdded' event?

<URL:http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclasscontroladdedtop ic.asp>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Phill,
In addition to deriving a new class from Control.ControlCollection and
overriding some of its methods. To get Control to use your new class you
need to override Control.CreateControlsInstance to create a new instance of
your ControlCollection.

However!! I would do as Herfried suggested & handle the Control.ControlAdded
& Control.ControlRemoved events.

Note the above are advanced members VB.NET normally hides them in both the
Object Browser & the code editor. Use "Show hidden members" in the object
browser to see them, use "Tools - Options - Text Editor - Basic - General -
Hide advanced members" to see them in the code editor.

Hope this helps
Jay

"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:c7**********@yarrow.open.ac.uk...
Is it possible to extend the Windows.Forms.Form.ControlCollection
class and override it's Add method?

I'm adding controls to a Form and want to [automatically] hook up
Event Handling for the Form to deal with on behalf of each Control.
I /thought/ the best way to do this would be to inherit from and
override the Add method on the Form.ControlCollection class and
put some AddHandler statements in there. This much I can do but the
bit I'm missing is how to get the Form to use /my/ ControlCollection
rather than the standard one.

Any suggestions?

TIA,
Phill W.

Nov 20 '05 #3
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Phill. W schrieb:
Is it possible to extend the Windows.Forms.Form.ControlCollection
class and override it's Add method?

I'm adding controls to a Form and want to [automatically] hook up
Event Handling for the Form to deal with on behalf of each Control.
I /thought/ the best way to do this would be to inherit from and
override the Add method on the Form.ControlCollection class and
put some AddHandler statements in there. This much I can do but the
bit I'm missing is how to get the Form to use /my/ ControlCollection
rather than the standard one.


Did you see the form's 'ControlAdded' event?

<URL:http://msdn.microsoft.com/library/en...ystemwindowsfo
rmscontrolclasscontroladdedtopic.asp>

Many thanks, Herfried; just what the Doctor ordered ...

And, of course, thanks once again to Our Friends in Redmond's
and their utterly /impenetrable/ documentation. ;-)

Regards,
Phill W.
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: James Marshall | last post by:
I'm trying to override location.replace() but I can't. I can override window.open(), document.write(), and other built-in methods, but not location.replace(). Here's a demo that overrides two...
0
by: Christo14 | last post by:
When I make a form with the form designer the result is a form with significantly fewer properties and meathods than if I made a form from scratch. The properties and meathods I currently have...
6
by: DraguVaso | last post by:
Hi, Is there actually a way to get ALL the Controls on a Form? While using the ControlCollection, it only returns the Controls that are directly on the Form, not the controls that are on a...
0
by: Harry F. Harrison | last post by:
Here's the situation...Context - Using an Inherited WebControl object as a base for server custom controls. In a web custom control, whenever I create a child control and add it to the Controls...
2
by: magister | last post by:
Hello, I have a asp.net page with a form with 15 textboxes and a couple of dropdownlists....I want to know if their is a way (...serverside please...) of checking if any change has been made to...
1
by: DanielSchaffer | last post by:
I am trying to create a class that inherits fromControlCollection, but I am getting the compile error "Nooverload for method 'ControlCollection' takes '0' arguments",and VS highlights the constructor...
2
by: D Hass | last post by:
Radio Buttons are added to my form During the Load event, the quantity determined by User input. They are placed in pairs on groupboxes with code like this: (edited a bit for brevity) Public...
2
by: Michael Beck | last post by:
I am new to .net programming and I want to know if I can loop thru a specified number of controls on an html form. In Access, the code looks like this: For i = 1 to 10 Me("txtAlternate" & i) =...
7
by: forest demon | last post by:
all i want is to do is to pass a form reference to a separate class and be able to manipulate properties/components/controls of said form. this should be as simple as passing a TextBox, Container...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.