In a control it is usefull in some cases to know if it is included on a
toolTip, HelpProvider etc. How do you access this information?
I have the code below which uses reflection to pickup the IContainter named
"Components" that the windows designer uses and this seem to work but I am
wondering if there is a way to do this without using reflection?
Anyone else have a better way of doing this???
/// <summary>
/// Method: This gets the ContainerControl and then looks for an
/// IContainer field named "components"
/// used by the windows designer. It uses reflection.
///
/// (can be used to look for ToolTips, ErrorProviders, HelpProviders etc)
/// </summary>
/// <returns></returns>
public IContainer GetContainerComponents(Control control)
{
IContainer components = null;
try
{
if (control.Container != null)
{
components = control.Container;
}
Object containerControl = control.GetContainerControl();
if (containerControl != null)
{
//Using Reflection to get components...
BindingFlags binding = BindingFlags.Instance
| BindingFlags.NonPublic
| BindingFlags.Public;
FieldInfo componentField
= containerControl.GetType().GetField("components",binding);
if (componentField != null)
{
components
= (IContainer)componentField.GetValue(containerControl);
}
}
}
catch {}
return components;
}
//Eg: Deactivates toolTips for a Control in
private void DeactivateControlToolTips(Control control)
{
IContainer components = GetContainerComponents(control);
foreach (Component child in components.Components)
{
if (child is System.Windows.Forms.ToolTip)
{
if ( ((System.Windows.Forms.ToolTip)child).GetToolTip(this).Length > 0)
{
((System.Windows.Forms.ToolTip)child).Active = false;
}
}
}
}