Tuesday, November 11, 2008

 

Navigating in Visual Studio

I work with Solutions that contain hundreds of files. Navigating through many levels of directories can be a cumbersome task, especially when you are not the author of the Solution. In university, using Visual Studio for assignments was never a problem, since you get to architect the structure of the Solution.

Working with a larger Solution, I was constantly performing Searches on desired keywords. This worked, but very time consuming. I needed to speed things up to increase my productivity. I wanted a mechanism to remember where sections of code are located within the Solution. Here are a couple of tips that can help:


 

Tip #1: Using Bookmarks

Visual Studio has a Bookmarks feature that allows you to save a specific line in a specific file. They work exactly like bookmarks used in web browsers. Simply press Ctl+k and Ctl+k to save the line as a bookmark. Note that you need to do Ctl+k twice, as I presume Visual Studio is starting to run out of shortcut keys! Once the bookmark has been saved, you can view the bookmark in the Bookmarks window that can be docked at the bottom of your window:


Instead of using the filename as the Bookmark title, try placing a comment as the title instead to remind yourself the importance of the said file, or even a "TODO" comment. I have a handful of bookmarks for files I have edited so I can quickly re-visit the file if need be.


 

Tip #2: Track item in Solution Explorer

Another tip to help navigate Visual Studio is to enable "Track Active Item in Solution Explorer". This allows any active file to be highlighted in the Solution Explorer. This comes in very handy when performing Searches, since double clicking a result highlights the file in Solution Explorer, giving you a general idea of the location of the file within the Solution.

This option can be enabled through Tools -> Options -> Projects and Solutions.


This behaviour is actually enabled by default, but for whatever reason, this feature was disabled one day. I went through days without this feature, so I finally made the effort to scan the long list of options under the Options dialog, and it was worth it!

Labels:


Sunday, October 12, 2008

 

Displaying Line Numbers in Visual Studio

You would think that the display of line numbers should just be automatic when using Visual Studio 2005 or 2008. After all when using a C# compiler all the errors are given by a line number. Also when exceptions occur the stack traces gives the line numbers of the stack (procedure calls) and the line number of the offending code that caused the exception. Unfortunately, by default the line numbers are not visible when viewing the code in Visual Studio. In fact many programmers work for months and even years before finding this important setting.

To display line numbering in Visual Studio 2005 or Visual Studio 2008 click the following sequence.

Tools/Options/Text Editor/C#/General and select "Display/Line Numbers".


Visual Studio C# text editor with line numbers off (default). Note no line numbers.


Select the Tools from the main menu bar, then Options.


Select Display/Numbers so that line numbers are displayed.


Visual Studio C# text editor with line numbers turned on. Note the line numbers on left.

Also See Related Postings
Using Regions
C#: Top 10 Coding Guidelines

Labels:


Tuesday, April 10, 2007

 

Make Use of #regions When Developing C# .net Code - Coding Guidlines Series

The is part of a .net Coding Guidelines series of blog postings.

Making code readable is an important consideration when developing and maintaining code. The single best way to make code more organized, thus more readable, is to use "region" compiler directive. Regions effectively group your code into sections and chapters.

This is a simple example of code without the region directive. The code is all there but even with just a few lines it can be difficult to read because nothing stands out. This only gets worse when the class is hundreds or thousands lines long.

Here is the same code with regions. It just looks a lot cleaner.

Now when you have found the selection that you want it is simply a matter of double clicking the region tag to see the details.

(example to be added)Even code with regions can get out hand when there are a large number of regions. Then it is time to group the regions into regions.

Labels: , ,


This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]