添加关闭按钮(红色的X)为.NET工具提示按钮、红色、提示、工具

2023-09-04 02:35:11 作者:倾城红颜醉

我正在寻找一种方式来增加一个关闭按钮类似于一个NotifyIcon的具有.NET工具提示对象。我使用的工具提示为所谓的编程与展()方法的消息气球。这工作正常,但没有onclick事件或简单的方法来关闭该提示。你必须调用隐藏()方法中的其他地方你code,我宁愿有提示能够关闭自己。我知道有大约使用管理和非托管code到与Windows API执行此净几个气球提示,但我宁愿留在我舒适的.NET世界中。我有我的调用.NET应用程序THRID第三方应用程序,并试图显示非托管工具提示,当它崩溃。

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.

推荐答案

您可以尝试通过重写现有的和定制OnDraw函数的实现自己的工具提示窗口。我从来没有尝试添加一个按钮,但做其他自定义的工具提示之前。

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     }