Visual Studio .NET Tips & Tricks

Helpful information for Visual Studio .NET developers

Archive for the ‘Coding & Debugging’ Category

Tip: Most useful shortcuts in VS.NET

Posted by Ion Toma on April 17, 2006

Switching between Windows:

Ctrl+F6  – navigate between various panes that appear in the base code editing window.
Shift+Alt+Enter – full-screen mode at any time. In full-screen mode, only the active window is visible in full screen.
Alt+F6/Alt +Shift+F6 – move cursor away from the main editing section into docked windows like Properties, Help, Dynamic help, Server Explorer (if these winows are open).
F7 – Jump to Code Behind/Base Code editing window

Ctrl+Shift+V   – cycle through the clipboard ring.
Ctrl+- (Ctrl + Hyphen) – similar with Internet Explorer, very easy to navigate from page to page.
Ctrl+Shift+- – cycles in the opposite direction.
Block Selection: – press Alt and then select the area you want with your mouse.
Line No in Code – Tools>Options>Text Editor>All Languages>General>Line numbers.
Ctrl+] :matching brace/comment/region/quote
F4: Property Window
Ctrl+Alt+L – Solution Explorer
Ctrl+Alt+O – Output Window
Ctrl+Alt+K – Task List
Ctrl+Shift+Space – intellisense window.
Ctrl+R – Word Wrap

Ctrl+K, Ctrl+K – Create/Remove Bookmark
Ctrl+K, Ctrl+N  – Move to next bookmark
Ctrl+K, Ctrl+P –  Move to previous bookmark
Ctrl+K, Ctrl+L – Clear all bookmarks

Code Format:
Ctrl+K, Ctrl+F – Auto-format selection
Ctrl+U – Convert to lower case
Ctrl+Shift+U – Convert to upper case
Ctrl+K, Ctrl+C – Comment selection
Ctrl+K, Ctrl+U – Uncomment selection

Code Outline:
Ctrl+M, Ctrl+M – Fold/Unfold the current code block
Ctrl+M, Ctrl+L – Unfold all
Ctrl+M, Ctrl+P – Stop outlining
Ctrl+M, Ctrl+O – Fold all

F5 – Start Application in debug Mode
Ctrl+F5 – Start Without debugging
F11 – Step into
F10 – Step over.
Shift + F11 – Step Out.
Shift + F5 – Stop debugging.
Ctrl+Shift+F5 – Restart Debugging.

Posted in Advanced, Beginner, Coding & Debugging, Intermediate, Miscellaneous, VS.NET 2003, VS.NET 2005 | Leave a Comment »

Tip: Bookmarks

Posted by Ion Toma on April 17, 2006

Bookmarks can be used to mark places in the code, like the code that you might want to jump back and forward. Bookmarks can be related to task list shortcuts, kind of the same functinality.

The bookmarks can be setup very easy, by pressing CTRL+K, CTRL+K to leave bookmark. For navigation, you can press CTRL+K, CTRL+N to move to the next bookmark, or CTRL+K,CTRL+P for the previous bookmark.


Flash Demonstration

Posted in Beginner, Coding & Debugging, Editor, VS.NET 2003, VS.NET 2005 | Leave a Comment »

Tip: Word-wrap

Posted by Ion Toma on April 17, 2006

In case we got code that goes too long, we have to scroll out of the screen to see the whole line.
In Visual Studio .NET, there is an option to wrap the text around, we don’t have to scroll horizontal to see the whole line

To wrap the text around, hit the following combination:
CTRL+R, CTRL+R in .NET 2003
CTRL+E CTRL+W in .NET 2005
Disadvantage: it make the code look a little bit messy.  But working with line numbers, this may be avoided. Tools > Options and select a checkbox that allows to see the line numbers.

Note: this tip can be used also in the case when we have to move the mouse over an error description to be able to see the long line. Just hit CTRL+R CRTL+R in Output pane and the error description will wrap around.

Posted in Beginner, Coding & Debugging, Editor, VS.NET 2003, VS.NET 2005 | Leave a Comment »

Tip: Add Line Numbers to Your Code-Behind Classes

Posted by Ion Toma on April 17, 2006

Adding Line numbers to your code can be very helpful when discussing the code with someone else. 


How to add line numbers to the code: from Tools menu, select Options, and then the Text Editor / C# or Basic options. Select then the "Line numbers" checkbox om the right-side.


Also, it works well with word wrap, you can see when a line starts and ends.
Another way to bring lines to your code is using Macro Explorer Tool window; there is a build in macro built-in that allows to turn on/off the line numbers.

Note: the line numbers are in the code, they are just displayed in a column to the left. 

Posted in Coding & Debugging, Editor, Intermediate, Testing, VS.NET 2003, VS.NET 2005 | Leave a Comment »

Tip: Treat Warnings as Errors

Posted by Ion Toma on April 16, 2006

A warning is a bug in waiting*. Warnings may be acceptable for debug builds, but for a release build, warnings must be always treated as errors. Zero-warnings should be as a rule for programmers, it is easy to ignore warnings, some of them may actually indicate a problem.
Warnings are the compiler's way of saying "this bit of code looks wrong, you better check it out“*. 

Others reasons:

  • It is bad practice to ship code that has compiler warnings in it. The compiler can help the developer, if the compiler generates an warning that means the developer must pay attention to it.
  • The customer may get some examples which contains sources. The warnings generated during compilation make the code look sloppy.

How to set it up: from Project Settings> Configuration Properties select the build setting and change the “treat warnings as errors” settings to true.Then set the warning levels to full, since we want to get all the help from the compiler as possible.

Warnings - Image 3


Posted in Coding & Debugging, Intermediate, Miscellaneous, VS.NET 2003, VS.NET 2005 | 2 Comments »

Tip: Custom Tasks List

Posted by Ion Toma on April 16, 2006

Custom task list is a great feature, which provides information about errors, annotations that a developer will leave in code.

Custom Task List - Image 1

There are some default tokens built-in in VS.NET. Example: TODO tokens (to finish some piece of code, etc).
The developer can create custom tokens for bugs, for notes that he/she want to leave to other developers on team that may work on the same code.

 – Go to  Options, select Task List, then enter a name for the CUSTOM TOKEN and click Add.

Custom Taks List - Image 2

Flash Demonstration

Posted in Coding & Debugging, Intermediate, VS.NET 2003, VS.NET 2005 | Leave a Comment »