1.思路。为字符串添加“\r\n”以表示换行。可以根据字符串的总长度,以及每行几个字,可以确定行数。
如图。是可换行tooltip
对应的主要代码如下:
1 private string GetToolTipText(string originalText, int countPerLine)
2 {
3 int modeInt;
4 string tempStr = string.Empty;
5 int toolTiptextLength = originalText.Length;
6 float linef = (float)toolTiptextLength / countPerLine;
7 double line = Math.Ceiling(linef);
8
9 if (toolTiptextLength > countPerLine)
10 {
11 for (int i = 0; i < line; i++)
12 {
13 modeInt = toolTiptextLength - i * countPerLine;
14 if (modeInt < countPerLine)
15 {
16 tempStr += originalText.Substring(i * countPerLine, modeInt);
17 }
18 else
19 {
20 tempStr += originalText.Substring(i * countPerLine, countPerLine);
21 tempStr += "\r\n";
22 }
23 }
24 }
25 else
26 {
27 tempStr = originalText;
28 }
29 return tempStr;
30 }
2 {
3 int modeInt;
4 string tempStr = string.Empty;
5 int toolTiptextLength = originalText.Length;
6 float linef = (float)toolTiptextLength / countPerLine;
7 double line = Math.Ceiling(linef);
8
9 if (toolTiptextLength > countPerLine)
10 {
11 for (int i = 0; i < line; i++)
12 {
13 modeInt = toolTiptextLength - i * countPerLine;
14 if (modeInt < countPerLine)
15 {
16 tempStr += originalText.Substring(i * countPerLine, modeInt);
17 }
18 else
19 {
20 tempStr += originalText.Substring(i * countPerLine, countPerLine);
21 tempStr += "\r\n";
22 }
23 }
24 }
25 else
26 {
27 tempStr = originalText;
28 }
29 return tempStr;
30 }