1

I am using a custom tooltip class in my WinForm application. It works great. But i would like to show it as a Balloon. Here is my code-

class CustomToolTip : ToolTip
{
    public CustomToolTip()
    {
        this.OwnerDraw = true;
        this.Popup += new PopupEventHandler(this.OnPopup);
        this.Draw += new DrawToolTipEventHandler(this.OnDraw);
    }

    private void OnPopup(object sender, PopupEventArgs e) // use this event to set the size of the tool tip
    {
        e.ToolTipSize = new Size(200, 100);
    }

    private void OnDraw(object sender, DrawToolTipEventArgs e) // use this event to customise the tool tip
    {
        Graphics g = e.Graphics;

        LinearGradientBrush b = new LinearGradientBrush(e.Bounds,
            Color.GreenYellow, Color.MintCream, 45f);

        g.FillRectangle(b, e.Bounds);

        g.DrawRectangle(new Pen(Brushes.Red, 1), new Rectangle(e.Bounds.X, e.Bounds.Y,
            e.Bounds.Width - 1, e.Bounds.Height - 1));

        g.DrawString(e.ToolTipText, new Font(e.Font, FontStyle.Bold), Brushes.Silver,
            new PointF(e.Bounds.X + 6, e.Bounds.Y + 6)); // shadow layer
        g.DrawString(e.ToolTipText, new Font(e.Font, FontStyle.Bold), Brushes.Black,
            new PointF(e.Bounds.X + 5, e.Bounds.Y + 5)); // top layer

        b.Dispose();
    }
}

Any suggestion?

Thanking you in anticipation.

s.k.paul
  • 7,099
  • 28
  • 93
  • 168

1 Answers1

1

You could just draw an ellipse then add a piece to point to the target.

But why not use the default tooltip control.

It has a IsBalloon flag that when set to true looks like this:

enter image description here

Community
  • 1
  • 1
string.Empty
  • 10,393
  • 4
  • 39
  • 67
  • Because I dont know how to set custom font size in default tooltip. I have collected this code from somewhere. If it is possible to set font size then definitely i'll use tooltip control. – s.k.paul Apr 04 '13 at 10:43
  • This looks promising: http://stackoverflow.com/questions/4657394/is-it-possible-to-change-toolstripmenuitem-tooltip-font – string.Empty Apr 04 '13 at 11:06