zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    Leetcode 349. Intersection of Two Arrays
    hdu 1016 Prime Ring Problem
    map 树木品种
    油田合并
    函数学习
    Leetcode 103. Binary Tree Zigzag Level Order Traversal
    Leetcode 102. Binary Tree Level Order Traversal
    Leetcode 101. Symmetric Tree
    poj 2524 Ubiquitous Religions(宗教信仰)
    pat 1009. 说反话 (20)
  • 原文地址:https://www.cnblogs.com/wyp1988/p/9896967.html
Copyright © 2011-2022 走看看