Click here to Skip to main content
6,635,160 members and growing! (14,385 online)
Email Password   helpLost your password?
Languages » C# » Applications     Intermediate

SnippetManager written by Tim Sneath extended with cool tooltip

By Andi Fleischmann

Ever find yourself hoarding little pieces of code that are always coming in handy? Snippet Manager is a little utility written in C# that collects all your code snippets into one convenient location, allowing you to save them into XML, or copy them into any code editor using the clipboard.
C#, Windows, .NET 1.0, Dev
Posted:11 Mar 2003
Views:44,747
Bookmarked:30 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
5 votes for this article.
Popularity: 2.33 Rating: 3.33 out of 5
1 vote, 20.0%
1

2
1 vote, 20.0%
3

4
3 votes, 60.0%
5

Sample Image - ExtendedSnippetManager.jpg

Introduction

I like the snippet manager written by Tim Sneath, but when I use it and have a lot of code snippets, I only can see the title of my snippet and can not remember, what is its content. So I added the functionality of a tooltip which provides me the contents. The tooltip is limited to 24 lines.  

Using the code

I only added a simple method to SnippetUI.cs, which receives a control and a message text as arguments and attaches a tooltip to the control.

  /// Attaches a tooltip to a control

  private void CreateToolTipForControl(Control ctl, String msg)
  {
   // split by carridge 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("...");
   } 

   // attache tooltip to control

   toolTip1.SetToolTip(ctl, sb.ToString());
  } 

This method is called everytime the toolwindow syncronizes its contents. 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Andi Fleischmann


Member

Occupation: Web Developer
Location: Germany Germany

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 2 of 2 (Total in Forum: 2) (Refresh)FirstPrevNext
GeneralHi, PinmemberJerry Maguire2:08 13 Mar '03  
GeneralRe: Hi, PinmemberDa Bert3:18 13 Mar '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 11 Mar 2003
Editor: Nishant Sivakumar
Copyright 2003 by Andi Fleischmann
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project