Intelli Sense Code Snippets

IntelliSense code snippets are a new .NET Framework feature supported by Visual Basic 2005. The IntelliSense code snippets are saved in XML files and become available in the Visual Studio IDE when you right-click the Code Editor and select Insert Snippet.

Visual Studio comes with a number of preinstalled snippets. When you select a code snippet to insert, an entire code block is inserted into the Code Editor. You can then customize the code for your application. For example, you can change the highlighted variable names to names you have defined in your application. Chapter 2 describes the default code snippets and the additional snippets you can download from www.microsoft.com.

You can insert an IntelliSense code snippet into the Code Editor in a number of ways. You can right-click the Code Editor, select Insert Snippet, and then navigate through the folders to the desired snippet. Or you can type the snippet's shortcut name and press the TAB key.

Another technique is to type the first few letters of the shortcut name, followed by a question mark (?), and then press the TAB key. A list of all the shortcuts that begin with the letters you typed appears in a dropdown list, and you can select the appropriate snippet. In addition to numerous preinstalled Visual Basic 2005 and VSTO code snippets that ship with Visual Studio, you can search for additional code snippets on the Internet, and you can create your own code snippets.

You create your own IntelliSense code snippets by creating an XML file that has a .snippet extension. You might find it useful to create these snippets to store frequently used functions as a type of function library for your projects. Instead of having to manually type the code or use the Toolbox as temporary storage for code snippets, you can create Intel-liSense code snippets and then quickly add complete procedures to your code. It's similar to storing autotext entries as you do in Word, but here, you insert them into the Code Editor. If you're interested in creating your own XML code snippets, you can find a description of how to manually create a simple code snippet in Appendix A.

0 0

Post a comment