Tim Sneath 编写的 SnippetManager 扩展了酷炫的工具提示






3.80/5 (5投票s)
2003 年 3 月 12 日

60537

923
你是否经常会积累一些总是派上用场的小段代码?Snippet Manager 是一个用 C# 编写的小工具,它可以将你所有的代码片段收集到一个方便的位置,允许你将它们保存到 XML 中,或者使用剪贴板将它们复制到任何代码编辑器中。
引言
我喜欢 Tim Sneath 编写的 Snippet Manager,但是当我使用它并且有很多代码片段时,我只能看到片段的标题,而无法记住它的内容。所以我添加了工具提示的功能,它可以向我提供内容。工具提示限制为 24 行。
Using the Code
我只是在 SnippetUI.cs 中添加了一个简单的方法,它接收一个控件和一个消息文本作为参数,并将工具提示附加到该控件上。
/// Attaches a tooltip to a control
private void CreateToolTipForControl(Control ctl, String msg)
{
// split by carriage return
String[] lines = msg.Split(new char[] {'\u000D'});
// StringBuilder is faster
StringBuilder sb = new StringBuilder();
// maximum lines
int lineCount = lines.Length;
if (lineCount > 24)
{
// only show 24 lines
lineCount = 24;
}
for (int i = 0; i < lineCount; i++)
{
// tab-character
char tab = '\u0009';
// line-feed-character
char lf = '\u000A';
// must replace tabs with whitespace to show properly
String line = lines[i].Replace(tab.ToString(), " ");
// must replace line-feeds to show properly
line = line.Replace(lf.ToString(), "");
// append String
sb.Append(line + "\n");
}
// append 3 dots if text exceeds more than 24 lines
if (lines.Length > lineCount)
{
sb.Append("...");
}
// attach tooltip to control
toolTip1.SetToolTip(ctl, sb.ToString());
}
每当 toolwindow
同步其内容时,都会调用此方法。
许可证
本文未附加明确的许可证,但可能在文章文本或下载文件本身中包含使用条款。如有疑问,请通过下面的讨论区联系作者。
作者可能使用的许可证列表可以在此处找到。