zoukankan      html  css  js  c++  java
  • Tooltips显示图片

    具体做法参见这篇文章,

    还有相关的帮助链接.

    需要注意的两点:

    OwnerDraw属性设置为true;

    IsBalloon属性不能设置为true;

    我起初把IsBalloon设置为true,

    结果图片怎么都显示不出来,

    修改为False后,

    图片顺利显示出来。

    为防止链接失效,

    把主要代码放在这里:

    private const int Margin = 10;
    
    // Set the tooltip's bounds.
    private void tipButtons_Popup(object sender, PopupEventArgs e)
    {
        int image_wid = 2 * Margin +
            Properties.Resources.happy.Width;
        int image_hgt = 2 * Margin +
            Properties.Resources.happy.Height;
    
        int wid = e.ToolTipSize.Width + 2 * Margin + image_wid;
        int hgt = e.ToolTipSize.Height;
        if (hgt < image_hgt) hgt = image_hgt;
    
        e.ToolTipSize = new Size(wid, hgt);
    }
    
    // Draw the tooltip.
    private void tipButtons_Draw(object sender, DrawToolTipEventArgs e)
    {
        // Draw the background and border.
        e.DrawBackground();
        e.DrawBorder();
    
        // Draw the image.
        e.Graphics.DrawImage(Properties.Resources.happy,
            Margin, Margin);
    
        // Draw the text.
        using (StringFormat sf = new StringFormat())
        {
            sf.Alignment = StringAlignment.Near;
            sf.LineAlignment = StringAlignment.Center;
    
            int image_wid = 2 * Margin +
                Properties.Resources.happy.Width;
    
            Rectangle rect = new Rectangle(image_wid, 0,
                e.Bounds.Width - image_wid, e.Bounds.Height);
            e.Graphics.DrawString(
                e.ToolTipText, e.Font, Brushes.Green, rect, sf);
        }
    }
    

    补充:

    文本需要换行的话,

    可以使用Environment.NewLine

    例如:

    this.toolTip1.SetToolTip(this.comboBox, "第一行文本," + Environment.NewLine + "第二行文本。");

    行距如何控制,

    尚未找到解决方法。

  • 相关阅读:
    数据库设计三大范式
    MySQL笔试题搜罗
    [转载]MySql事物处理
    网页错误代码大全
    【转载】linux环境下大数据网站搬家
    Linux常用命令
    MongoDB概述
    Linux系统下通过命令行对mysql数据进行备份和还原
    wamp提示:与服务器的连接断开,请检查网络状况与服务器的运行状态的解决方法
    HDU 4578 线段树各种区间操作
  • 原文地址:https://www.cnblogs.com/myzw/p/14032777.html
Copyright © 2011-2022 走看看