• WinForm中使用自定义Tooltip控件


    • private ToolTip tooltipCtr;
    • 构造函数中:
      • 隐藏默认的Tooltip:this.ShowCellToolTips = false;
      • this.tooltipCtr = new ToolTip();
      • 设置停留时间(还有许多其他时间设置):this.tooltipCtr.AutoPopDelay = 1000 * 60;
      • 在CellMouseEnterHandler等事件中设置数据,在鼠标处设置文本:tooltipCtr.Show(HttpUtility.HtmlDecode(((BasicData)this.Rows[rowIndex].DataBoundItem).VarDescLong), this, PointToClient(MousePosition));
      • 限制宽度/每行字符数(自动换行)
        •  1         private const int maximumSingleLineTooltipLength = 120;
           2 
           3         private static string AddNewLinesForTooltip(string text)
           4         {
           5             if (text.Length < maximumSingleLineTooltipLength)
           6                 return text;
           7 
           8             StringBuilder sb = new StringBuilder();
           9 
          10             int currentLinePosition = 0;
          11             for (int textIndex = 0; textIndex < text.Length; textIndex++)
          12             {
          13                 sb.Append(text[textIndex]);
          14 
          15                 // if reach the original new line in the text
          16                 // just recount
          17                 if (text[textIndex].Equals(Environment.NewLine)
          18                     || (text[textIndex].Equals('
          ') && textIndex >= 1 && text[textIndex - 1].Equals('
          ')))
          19                 {
          20                     currentLinePosition = 0;
          21                     continue;
          22                 }
          23 
          24                 // If we have reached the target line length 
          25                 // and the nextcharacter is whitespace 
          26                 // and don't break 
          
          27                 // then begin a new line.
          28                 if (currentLinePosition >= maximumSingleLineTooltipLength
          29                     && char.IsWhiteSpace(text[textIndex])
          30                     && !(text[textIndex].Equals('
          ') && textIndex < text.Length && text[textIndex + 1].Equals('
          ')))
          31                 {
          32                     sb.Append(Environment.NewLine);
          33                     currentLinePosition = 0;
          34                     continue;
          35                 }
          36 
          37                 // Append the next character.
          38                 if (textIndex < text.Length)
          39                 {
          40                     currentLinePosition++;
          41                 }
          42             }
          43 
          44             return sb.ToString();
          45         }
          View Code
  • 相关阅读:
    0907 安装 Pycharm
    zabbix监控redis多实例(low level discovery)
    zabbix3.0配置邮件报警
    zabbix通过jmx监控tomcat
    分布式文件系统FastDFS安装与配置(单机)
    nginx+tomcat配置https
    利用python分析nginx日志
    查找IP来源
    清除nginx静态资源缓存
    Nginx缓存配置及nginx ngx_cache_purge模块的使用
  • 原文地址:https://www.cnblogs.com/wyp1988/p/9896967.html
Copyright © 2020-2023  润新知