Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBControlExtender (with design time control)

Status
Not open for further replies.

mmilan

Programmer
Jan 22, 2002
839
GB
Hi Everyone,

I'm in the process of writing a DLL library, the idea of which is to watch controls for various events (let's keep this simple and just say Focus for now)... I've got the code sorted out in terms of tracking the events that we'd like to watch, but the actual watching is proving troublesome!

My first attempt at this was to declare a seperate class to wrap each class of control I was interested in, and give these wrapper classes a common interface. My focus manager would then be free to store these wrapper objects - and use the common interface to be able to get back to the underlying control. All seemed well.

In terms of watching for the events, each wrapper would hold a reference for the associated control type declared using "WithEvents" - therefore allowing my wrapper object to read the event of the associated control. My first few tests were wonderfully successful...

Unfortunately however, I have found that it doesn't work with elements that are in control arrays - because when you think about it those elements are trying to add an "Index" argument to the event signatures, which is not supported by the events on my reference within the wrapper...

I've come across a class called VBControlExtender, and if I could only get it to work this could solve all my problems - as well as meaning I would only need one, single, solitary wrapper class for everything - which has a certain appeal.

My question then (here it comes) - if I have say a Textbox that was added to a form at DESIGN time - how do I get my hands on a corresponding VBControlExtender object for it. The only examples I've seen thus far involve the creation of objects using Form.Controls.Add - ie dynamic - which isn't what I'm trying to do...

My thanks in anticipation of anyone who feels like providing a burst of inspiration...

Martin
 
You're talking about adding a level of indirection between the client and the server, so that you can preprocess the output of the server before presenting it to the client.

I did this job "manually", personally. You don't really need to wrap each class, rather you need to create a class that handles the interaction between the entities, say a "broker" class. Define each event you want to raise in the broker class. Now, have the control instantiate this class (or if it exists, reference an existing instance--look up "singleton pattern") and expose the reference to the class as a property of itself. Have the client declare an instance of this class also, and reference the same instance that the control does (by setting the class variable equal to the property on the control that references the same object).

This should allow you the flexibility to do what you want. For detail on a similar project, check faq222-3666, and feel free to post back with specific questions if you like.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top