Chapter 2. The Development Environment
Introduction Recipe 2.1. Discovering and Using a Code Snippet Recipe 2.2. Creating a New Snippet Recipe 2.3. Sharing Snippets Recipe 2.4. Adding Snippet Files to Visual Studio Recipe 2.5. Getting an Application's Version Number Recipe 2.6. Letting Visual Studio Automatically Update an Application's Version Number Recipe 2.7. Setting the Startup Form for an Application Recipe 2.8. Setting the Startup to a Sub Main Procedure Recipe 2.9. Getting an Application's Command Line Recipe 2.10. Testing an Application's Command Line Recipe 2.11. Obfuscating an Application Recipe 2.12. Determining if an Application Is Running in the Visual Studio Environment Recipe 2.13. Accessing Environment Variables Recipe 2.14. Accessing the Registry Recipe 2.15. Getting System Information
Recipe 2.16. Getting the User's
|
IntroductionDid you know that the Visual Basic 2005 compiler is available to you free of charge? You can download the .NET Framework with all included compilers directly from Microsoft's web site, and start using it immediately to develop and distribute your own .NET applications, all without shelling out a single penny. Well, there are a few caveats. The main one is that you will have to use a tool such as Notepad to write all of your source code. And you will need to hand-type the statements that start the compilation process through the Windows Command Prompt. But other than that, it's a piece of cake. And it's still free. If you're not that bold, you should probably fork over a little cash to obtain Visual Studio, the programming environment of choice for .NET application development. Although it's not free, you definitely get what you pay for.(Actually, Visual Basic 2005 Express Edition is free, so you get even more than you pay for.) Visual Studio is stuffed with features and support tools and visual designers and behind-the-scenes automatic code generation wizards, all of which let you concentrate on developing great code without having to worry about the picky details of setting up the compiler and deployment options. This chapter discusses some of the snazzy features included with Visual Studio 2005. As with all the chapters in this book, we have concentrated on Visual Studio 2005 Professional Edition. However, most, if not all, recipes in this book should work with any edition of Visual Studio. |
Recipe 2.1. Discovering and Using a Code SnippetProblemYou know that Visual Studio came with a bunch of prewritten "snippets" that you can use in your applications, but you don't know where to find them in the vast Visual Studio menu system. Solution
Code snippets are among the IntelliSense features included with Visual Studio. To find and insert a snippet, use the different snippet-
DiscussionTo insert a code snippet into your source code, right-click at the desired location with the mouse, choose Insert Snippet from the shortcut menu (Figure 2-1), and navigate to the snippet you want to use. Figure 2-1. Inserting a snippet with the mouse
An even faster method is to type a question mark ( ?)
Using any of these
Figure 2-2. Primary snippet categories
To negotiate the hierarchy, use the mouse or arrow keys to select a folder or item in the pop-up list, or type a partial list
Each snippet contains a useful block of prewritten code, but many also include some intelligence. Some snippets include "fill in the blank" templates that provide areas for you to supply your custom values. For instance, the Data Typesdefined by Visual Basic
Dim hexString As String = Hex( 48 )
Some snippets place multiple lines of source code in the code editor, sometimes with multiple replacement fields. The Common Code Patterns
Structure MyStructure Public ValueOne As Integer Public ValueTwo As Boolean End Structure
Some snippets add code to various places in your source-code file and may make other updates to your project. The Security
Snippets are somewhat location-dependent. Most are written to be used inside a sub-routine, function, or property accessor, while a few are designed for placement out-side of routines or classes. If you insert a snippet at the top of a source-code file, outside of any class context, it will be riddled with errors. Snippets are actually specially formatted XML files, with attributes containing the special insertion rules for each snippet. See AlsoRecipes 2.2, 2.3, and 2.4 provide additional information on code snippets. |