Click here to Skip to main content
13,044,705 members (51,995 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi All,

I have a query which is "how" does a tooltip manage to Add the ToolTip (Text) property to every control on the form automatically.

I have searched but cannot think of how this may be achieved, other than litterally inheriting and extending classes =/.

Is there a way of appending a new property to an existing control purely through code.

Any help would be apreciated,

Thanks George
Posted 24-Jan-12 23:43pm
Updated 25-Jan-12 3:09am
Shahin Khorshidnia 25-Jan-12 6:00am
Windows user control, Asp.Net or WPF ?
grwithey 25-Jan-12 8:21am
Ah yes its also in .Net (c#) windows forms controls
jai000 25-Jan-12 8:09am
You can create your own custom control and you can add your own property to this custom control. Check following link
grwithey 25-Jan-12 8:19am
Hi both thanks for the response.

I think the answer i am after may be a little more complex or impossible. I was looking for the same functionality as the ToolTip control "appears" to impliment in that it adds an extra property to every control in the form.

My theory as to what is happening is that the tool tip itself stores a dictionary with a list of control references which in turn relate to a text value "the (ToolTip ToolTip1") text property that appears on all controls. I think that each controls "PropertyGrid" is in some way displaying the property stored by the Tool tip that relates to that particular control.

This is a theory and would be good to know if this is right as in that case the solution would be how could i programatically append a property to a controls grid?

Thanks George

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I think you can clarify your question, and, perhaps, get more focused responses, if you share what exactly you are trying to achieve here in a specific, concrete example. The title of your question: "How to programatically add properties to a user control," could be interpreted a variety of ways, but the content of your question seems to focus on duplicating a ToolTip's functionality.

If I focused on just the title of your question, my responses might mention techniques involving run-time modification using Reflection, or extension of UserControls via inheritance or Interfaces (design-time), and more.

I think (guess) what you are looking for here is how to build an "Extender Provider:" Control/Component: in WinForms, the ToolTip is a kind of strange "hybrid" Control that is both a Control, and a Component: it implements Extender Provider.

In any case, be sure and review this discussion here: [^], and I'd look carefully at OriginalGriff's code suggestions.

Microsoft's documentation on WinForms ToolTip is ambiguous: you will find it both documented as a Component, which it is, and as a Control.

The ToolTip class is defined as inheriting from both Component, and IExtenderProvider.
public class ToolTip : Component, IExtenderProvider
Suggest you start by looking at these MSDN resources: [^], and: [^].

And then do a CP search: start here: [^] : you'll find many useful articles like these "oldies:" [^], and [^].
grwithey 24-Feb-12 7:01am
Thanks Bill this was in fact the solution i was looking for, i was trying to find a way of duplicating the functionality of the tooltip and the information you provided was helpful

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 25 Jan 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100