Quick Visual Studio .NET Tips

Friday Aug 5th 2005 by Karl Moore

Still getting used to Visual Studio .NET? Here are a handful of little-known Visual Studio tips sure to make your life easier...

Still getting used to Visual Studio .NET? Here are a handful of little-known Visual Studio tips sure to make your life easier...

Writing a Developer TODO: List

The Task window in VB.NET is a great way of keeping track of tasks that are related to your project. For example, if you have code issues or compile errors, VB.NET will automatically list them here.

You also can add your own comments to the Task list, with the TODO keyword. To use this feature, simply add a comment to your code that starts with the TODO keyword. It will automatically be added to your existing Task list. For example:

' TODO: Rewrite function so works with .DOC files

To view the Task list, select View > Other Windows > Task List from the menu, or press Ctrl+Alt+K. The Task list often filters its contents, so it displays only certain information. To view everything, right-click on your list and select All Tasks > All.

Top Tip: Fed up with the TODO keyword? Users of Visual Studio .NET 2003 (Everett) have automatic support for the "HACK" prefix, which works in the exact same way as TODO, yet attracts much more kudos. You can edit the Task list keywords yourself by editing the values in Tools > Options > Environment > Task List.

Click here for a larger image.

Figure: If only all TODO lists were this short...

Storing Often-Used Code in the Toolbox

There's an easy way to store often-used code and templates in VS .NET. Simply drag and drop your code straight onto one of the toolbox tabs, such as the General tab. When you need to use it again, simply drag and drop back into your code window. And, best of all, these snippets persist from project to project, saving even more development time.

Click here for a larger image.

Figure: Adding code to the toolbox

Organizing your Project with Folders

Overwhelmed with the number of files that now make up your application? Starting to lose track of which .VB files do what? Well, there's a simple method of keeping track. Use folders!

Right-click on your project in the Solution Explorer and select Add > New Folder. Then, simply drag-and-drop your existing code files into the new folders. For example, you may have one folder called "User Interface" to store your forms. Or a folder called "Database Code" to store your data access classes.

Don't worry: there's no extra configuration required; your entire project compiles as normal with no extra effort. It simply allows you to organize your project the way it should be.

A simple tip, but one that can turn chaos into control within minutes.

Figure: One of my company C# projects, really taking advantage of folders

Discovering Whether You're Running in the IDE

Previous versions of Visual Basic made it easy to figure out whether you were running your application through the IDE (Integrated Development Environment). It simply allowed you to check which "mode" your application was in. VB .NET, however, isn't quite as easy-going.

The most common method of figuring out whether the application is running in the .NET IDE is to check the System.Diagnostics.Debugger.IsAttached property to determine whether a debugger is attached to the currently executing code. If so, you can safely assume your code is running from within the IDE.

If you're designing your own controls, you might also run into the situation where your code is running in design modewhile you only want it to execute during 'full' runtime. In this situation, simply check the DesignMode property of your component (that is, from inside your control: Me.DesignMode). If it returns True, you're running in the IDEb—so cut your code short.

A simple solution to a common question, and definitely worth remembering.

# # #

Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved