【问题标题】:Display custom tooltip as Balloon将自定义工具提示显示为气球
【发布时间】:2013-04-04 08:22:35
【问题描述】:

我在我的 WinForm 应用程序中使用自定义工具提示类。它工作得很好。但我想把它展示为一个气球。这是我的代码-

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

有什么建议吗?

谢谢你的期待。

【问题讨论】:

  • 为什么不使用默认的工具提示控件?

标签: winforms tooltip


【解决方案1】:

你可以画一个椭圆,然后添加一块指向目标。

但是为什么不使用默认的工具提示控件呢。

它有一个 IsBalloon 标志,当设置为 true 时看起来像这样:

【讨论】:

  • 因为我不知道如何在默认工具提示中设置自定义字体大小。我从某个地方收集了这段代码。如果可以设置字体大小,那么我肯定会使用工具提示控件。
  • 这看起来很有希望:stackoverflow.com/questions/4657394/…
猜你喜欢
  • 1970-01-01
  • 2011-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-11
相关资源
最近更新 更多