views:

970

answers:

1

I'm looking for a way to add a close button to a .NET ToolTip object similar to the one the NotifyIcon has. I'm using the tooltip as a message balloon called programatically with the Show() method. That works fine but there is no onclick event or easy way to close the tooltip. You have to call the Hide() method somewhere else in your code and I would rather have the tooltip be able to close itself. I know there are several balloon tooltips around the net that use manage and unmanaged code to perform this with the windows API, but I would rather stay in my comfy .NET world. I have a thrid party application that calls my .NET application and it has crashes when trying to display unmanaged tooltips.

+1  A: 

You could try an implement your own tool tip window by overriding the existing one and customizing the onDraw function. I never tried adding a button, but have done other customizations with the tooltip before.

    1    class MyToolTip : ToolTip

    2     {

    3         public MyToolTip()

    4         {

    5             this.OwnerDraw = true;

    6             this.Draw += new DrawToolTipEventHandler(OnDraw);

    7 

    8         }

    9 

   10         public MyToolTip(System.ComponentModel.IContainer Cont)

   11         {

   12             this.OwnerDraw = true;

   13             this.Draw += new DrawToolTipEventHandler(OnDraw);

   14         }

   15 

   16         private void OnDraw(object sender, DrawToolTipEventArgs e)

   17         {

                      ...Code Stuff...

   24         }

   25     }
avgbody