Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 25-Jan-12 0:43am
Edited 25-Jan-12 4:09am
ambarishtv10.5K
v2
Comments
Shahin Khorshidnia at 25-Jan-12 6:00am
   
Windows user control, Asp.Net or WPF ?
grwithey at 25-Jan-12 8:21am
   
Ah yes its also in .Net (c#) windows forms controls
jai000 at 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
http://www.codeproject.com/Articles/2016/Writing-your-Custom-Control-step-by-step
grwithey at 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
good
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 [^].
  Permalink  
v2
Comments
grwithey at 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
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 25 Jan 2012
Copyright © CodeProject, 1999-2014
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