Tooltip on UserControls with Child Controls

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);
}

}
 
B

Bruce Wood

I'm doing it the same way your are, but I saw someone else here
mentioning using the MouseHover event and creating the ToolTip object
in the event handler. I haven't tried it myself.
 
G

Guest

Thanks for the replay....

I actualy do that in a variety of controls, especially TreeView when over
the node.... I have also found that you need to stop it being active, assign
the text
and then make it active for it to work in some places.

eg:

private void SetToolTip (Control control,string toolTipText)
{
if ( ToolTipsActive //Property that displays tooltips on the control
&& this.ToolTip != null
&& this.ToolTip.GetToolTip(control) != toolTipText )
{
this.ToolTip.Active = false;
this.ToolTip.SetToolTip(control,toolTipText);
this.ToolTip.Active = true;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top