G
Guest
It seems inelegant to get a UserControl with Child Controls to display a
tooltip.
According to the documentation you just set ToolTip.ShowAlways = true;
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfSystemWindowsFormsToolTipClassShowAlwaysTopic.htm
This feature is also useful when creating a control using the UserControl
that contains a number of controls within it that display ToolTip windows.
Since the UserControl is often not the active window on a form, setting this
property to true enables the controls within the UserControl to display
ToolTip windows at any time.
This does not work for me? Is there something obvious that I am missing.
I have implemented the code below to get my custom controls to work but just
seems like I am missing something obvious here..
How are you doing this?
/// <summary>
/// Field: ToolTip component to be used for setting ToolTipText
/// </summary>
private System.Windows.Forms.ToolTip toolTip;
/// <summary>
/// Property: Gets or Sets ToolTip component to be used for setting
ToolTipText
/// Note: If null and Text is entered in ToolTipText a new ToolTip object
will be
/// created just for this NumberBox to use
/// </summary>
[Browsable(true)
,DefaultValue(null)
,Category("Misc")]
public System.Windows.Forms.ToolTip ToolTip
{
[DebuggerStepThrough()]
get { return toolTip; }
[DebuggerStepThrough()]
set { toolTip = value; SetToolTipText(); }
}
/// <summary>
/// Field: Text that appears on the ToolTip
/// </summary>
private string toolTipText;
/// <summary>
/// Property: Gets or Sets Text that appears on the ToolTip
/// </summary>
[Browsable(true)
,DefaultValue("")
,Category("Misc")]
public string ToolTipText
{
[DebuggerStepThrough()]
get { return toolTipText; }
[DebuggerStepThrough()]
set { toolTipText = value; SetToolTipText(); }
}
/// <summary>
/// Method: Sets the ToolTip Text
///
/// Note: if ToolTip is null and Text is entered in ToolTipText
/// a new ToolTip object will be created just for this NumberBox to use
/// if want it to use a common ToolTip set the NumberBox.ToolTip property
/// </summary>
private void SetToolTipText()
{
string tipText = string.Empty;
//Is there toolTipe text???
if (ToolTipText != null && ToolTipText.Length > 0)
{
tipText = ToolTipText;
}
//If text and no tool tip then one need to be created
if (this.ToolTip == null && tipText.Length > 0)
{
this.toolTip = new ToolTip();
this.toolTip.Active = true;
this.toolTip.ShowAlways = true;
}
// If tool Tip present then set the tip for it and all controls
if (this.ToolTip != null)
{
this.ToolTip.SetToolTip(this,tipText);
this.ToolTip.SetToolTip(this.TextBox,tipText);
this.ToolTip.SetToolTip(this.MinusButton,tipText);
this.ToolTip.SetToolTip(this.PlusButton,tipText);
}
}
tooltip.
According to the documentation you just set ToolTip.ShowAlways = true;
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfSystemWindowsFormsToolTipClassShowAlwaysTopic.htm
This feature is also useful when creating a control using the UserControl
that contains a number of controls within it that display ToolTip windows.
Since the UserControl is often not the active window on a form, setting this
property to true enables the controls within the UserControl to display
ToolTip windows at any time.
This does not work for me? Is there something obvious that I am missing.
I have implemented the code below to get my custom controls to work but just
seems like I am missing something obvious here..
How are you doing this?
/// <summary>
/// Field: ToolTip component to be used for setting ToolTipText
/// </summary>
private System.Windows.Forms.ToolTip toolTip;
/// <summary>
/// Property: Gets or Sets ToolTip component to be used for setting
ToolTipText
/// Note: If null and Text is entered in ToolTipText a new ToolTip object
will be
/// created just for this NumberBox to use
/// </summary>
[Browsable(true)
,DefaultValue(null)
,Category("Misc")]
public System.Windows.Forms.ToolTip ToolTip
{
[DebuggerStepThrough()]
get { return toolTip; }
[DebuggerStepThrough()]
set { toolTip = value; SetToolTipText(); }
}
/// <summary>
/// Field: Text that appears on the ToolTip
/// </summary>
private string toolTipText;
/// <summary>
/// Property: Gets or Sets Text that appears on the ToolTip
/// </summary>
[Browsable(true)
,DefaultValue("")
,Category("Misc")]
public string ToolTipText
{
[DebuggerStepThrough()]
get { return toolTipText; }
[DebuggerStepThrough()]
set { toolTipText = value; SetToolTipText(); }
}
/// <summary>
/// Method: Sets the ToolTip Text
///
/// Note: if ToolTip is null and Text is entered in ToolTipText
/// a new ToolTip object will be created just for this NumberBox to use
/// if want it to use a common ToolTip set the NumberBox.ToolTip property
/// </summary>
private void SetToolTipText()
{
string tipText = string.Empty;
//Is there toolTipe text???
if (ToolTipText != null && ToolTipText.Length > 0)
{
tipText = ToolTipText;
}
//If text and no tool tip then one need to be created
if (this.ToolTip == null && tipText.Length > 0)
{
this.toolTip = new ToolTip();
this.toolTip.Active = true;
this.toolTip.ShowAlways = true;
}
// If tool Tip present then set the tip for it and all controls
if (this.ToolTip != null)
{
this.ToolTip.SetToolTip(this,tipText);
this.ToolTip.SetToolTip(this.TextBox,tipText);
this.ToolTip.SetToolTip(this.MinusButton,tipText);
this.ToolTip.SetToolTip(this.PlusButton,tipText);
}
}