Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Textbox Balloon Tooltip .NET 2

0.00/5 (No votes)
28 Dec 2012 1  
Balloon tool tip for the text box.

Introduction 

Balloon tool tip for the text box. This sample code can be used to display the balloon tool tip at caret position.

Background 

The balloon tool tip was not getting displayed at the proper caret position in the text box. So did a work around for the same.

Using the code

If you want to display the balloon tool tip at the caret position. Use this sample code in your project and modify accordingly.

class CustomToolTip : ToolTip
{
    Control textBox;
    public CustomToolTip(Control ctrl)
    {
        textBox = ctrl;
        this.OwnerDraw = true;
        this.IsBalloon = true;   // If wont set this to true, it will display in a rectangle.
        this.ToolTipIcon = System.Windows.Forms.ToolTipIcon.Info;
        this.ToolTipTitle = "Title";   // This is displayed as the Title
    }

    public void ShowToolTip()
    {
        this.UseAnimation = true;
        Graphics g = textBox.CreateGraphics();
        // Get the exact width of the string
        int width = (int)g.MeasureString(textBox.Text, textBox.Font).Width;
        g.Dispose();
        this.Show(string.Empty, textBox, 0);
          // There is a bug in the tool tip. So display an empty string
          // for 0ms before displaying the actual string. 

       this.Show("Display String", textBox, width, textBox.Height, 3000);
    }
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here