private const int maximumSingleLineTooltipLength = ;
private static string AddNewLinesForTooltip(string text)
{
if (text.Length < maximumSingleLineTooltipLength)
return text;
StringBuilder sb = new StringBuilder();
int currentLinePosition = ;
for (int textIndex = ; textIndex < text.Length; textIndex++)
{
sb.Append(text[textIndex]);
// if reach the original new line in the text
// just recount
if (text[textIndex].Equals(Environment.NewLine)
|| (text[textIndex].Equals('\n') && textIndex >= && text[textIndex - ].Equals('\r')))
{
currentLinePosition = ;
continue;
}
// If we have reached the target line length
// and the nextcharacter is whitespace
// and don't break \r\n
// then begin a new line.
if (currentLinePosition >= maximumSingleLineTooltipLength
&& char.IsWhiteSpace(text[textIndex])
&& !(text[textIndex].Equals('\r') && textIndex < text.Length && text[textIndex + ].Equals('\n')))
{
sb.Append(Environment.NewLine);
currentLinePosition = ;
continue;
}
// Append the next character.
if (textIndex < text.Length)
{
currentLinePosition++;
}
}
return sb.ToString();
}