如何制作自定义工具提示样式

时间:2014-02-21 12:22:38

标签: c# popup containers mouseover popupwindow

如何为文字信息制作自定义工具提示设计?我只知道如何更改backColor或foreColor。但我想用于工具提示段落,行,分隔符和图标。

如此图片:

我的剧本:

class descriptionSpells
{
    ToolTip popup = new ToolTip();
    string description = "test";
    string range = "15";
    string radius = "2";
    string castTime = "Instant";
    string duration = "5";

    public descriptionSpells(object sender)
    {
        popup.OwnerDraw = true;
        popup.Popup += new PopupEventHandler(this.OnPopup);
        popup.SetToolTip((Button)sender, description + radius + range + castTime + duration);
        popup.Draw += description_Draw;
    }

    private void OnPopup(object sender, PopupEventArgs e)
    {
        e.ToolTipSize = new Size(200, 100);
    }

    private void description_Draw(object sender, DrawToolTipEventArgs e)
    {
        Graphics g = e.Graphics;

        LinearGradientBrush b = new LinearGradientBrush(e.Bounds,
            Color.BurlyWood, Color.Gray, 45f);

        g.FillRectangle(b, e.Bounds);

        g.DrawRectangle(new Pen(Brushes.Black, 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));
        g.DrawString(e.ToolTipText, new Font(e.Font, FontStyle.Bold), Brushes.Black,
            new PointF(e.Bounds.X + 5, e.Bounds.Y + 5));
        b.Dispose();
    }
}

0 个答案:

没有答案