Tap into the Power of Visual Studio
Daily coding is a lot easier when you know how to use Visual Studio effectively. To optimize your experience with the latest Microsoft IDE, try these practical tips and shortcuts. (Part 2 of 3)
In the first part of this three-part series on getting the most out of Visual Studio 2010, we looked at some tips that can help developers get started with the new version and personalize the layout of the user interface. In this installment, we look the updated project dialog in Visual Studio 2010, as well as opportunities to improve navigation.
Updated Project Dialog
Once you're ready to start a project, you'll find an updated New Project dialog (see Figure 1), where I've delineated the most easily overlooked features. You can finally search and sort items in this dialog! The search evaluates all available projects so you'll see C# and Visual Basic projects both displayed. If you'd like to narrow it down to a particular project type, add C# or Visual Basic as a separate word at the end of your search string. The previous word doesn't need to be complete; for example, "cl c#" finds the C# Class Library, C# Silverlight Class Library and several other project types.
[Click on image for larger view.]
|Figure 1. PLINQ adds query analysis and standard query operators to the functionality in the Task Parallel Library (TPL). TPL provides the basic constructs, structures and scheduling required to manage the underlying threads of the OS.|
You can select the target platform in the New Project dialog. If you develop Windows Presentation Foundation (WPF) or Windows Forms applications, you might be surprised to find the default target platform for Visual Studio 2010 is the Client Profile. This is a subset of the full Microsoft .NET Framework platform designed for faster and smaller installation. In most cases, this is a good choice for your application, but be prepared to change it if you're missing aspects of the framework that you need.
If you've seen a demo of Visual Studio 2010, you've probably seen zoom via the scroll wheel or control-shift-comma and period. It's a flashy and easily misunderstood feature. Similar to Excel zoom, only the current tab zooms. The zoom doesn't "stick." The intention is not to change your font size overall, such as for a presentation, but to allow different views of different windows and at different times. You can zoom out to get the big picture or zoom in to see the details of your code.
I frequently want to change the font size for all of my text editor windows when I move from my external monitor to laptop screen, hook up to a projector, pair with someone, or when my eyes are just having a bad day. You can map a key to increase or decrease your font size for all of your code windows using an accessibility macro. Search keyboard mappings for "fontsize," and you should find Macros.Samples.Accessibility.DecreaseTextEditorFontSize and its parallel InCreaseTextEditorFontSize. I map these to Alt-Minus and Alt-Equals, which are easy for me to remember. You can do this in Visual Studio 2008 and Visual Studio 2010.
Navigating between your open windows continues to improve with each version of Visual Studio. Ctl-Tab displays a navigable list of available windows and Ctl-F6/Ctl-Shift-F6 navigates through tabs. Ctl-Minus and Ctl-Shift-Minus now offer a slightly different behavior, which navigates only through text editor (code) tabs, skipping designers. You can access the drop-down list of open tabs with Ctl-Alt-Down, or if this fails, key map searching on "EzMdi." Once dropped down, you can navigate to a specific tab either with the mouse or by typing the initial characters of the name. A subtle aspect of the drop-down is that the drop-down arrow changes when there are tabs out of view. The trick of navigating by typing the name also works when navigating in Solution Explorer.
Windows themselves become more flexible in Visual Studio 2010. All windows can separate from Visual Studio, which is particularly useful when you drag them to a second monitor. Tool windows remain in a dockable state at all times, making rearrangement easier. The float option remains, but its purpose is to float a single item of a set of tabbed and docked windows. Dragging the title bar moves the set. In both cases, simply dragging to a dock location redocks, and dropping on a title bar adds to that tabbed set. Tool windows can now become tabs in the main window.
Within a code window you can navigate backward and forward using the back and forward buttons or keyboard shortcuts (which differ by keyboard layout). The Navigate To dialog box is new to Visual Studio 2010 and can be accessed via the Edit menu or a shortcut key. This feature has sometimes been called "Quick Search." It allows navigation to any symbol (such as a type or method) in your project and is cached for very fast performance. The search is based on a Pascal-style search, which assumes every capital letter or underscore in your symbol name delimits a word you might search on. A special trick is to include a space in your search string to find two different word parts based on a partial search. For example, "bi att" finds BizServiceAttribute and BizObjectAttribute. If you type capital letters, Visual Studio 2010 will evaluate them as an abbreviation, so BSA will also retrieve BizServiceAttribute as one of the matching options. This new dialog is especially useful when you're not quite sure of the name. It enhances the benefits of good, semantic, multipart naming.
The Visual Studio 2010 editor has a feature that at first glance may seem a little odd. Hovering the cursor over a symbol highlights all matching symbols. This illustrates how symbols are used, particularly if you temporarily zoom out. What's cool is you can navigate between the highlighted words using Ctl-Shift up and down arrows. If you don't like this feature, you can turn it off in the Tool/Options page for each language.
C# and C++ have a special navigation feature called Call Hierarchy that's shown in Figure 2. Call Hierarchy allows exploration and navigation based on the ways methods are used, jumping to call sites and to called members. While this has some similarities to the runtime callstack, it's available at design time and shows all potential paths, not just the single, currently executing path. Call Hierarchy is an extremely valuable tool. Hopefully, Visual Basic will support Call Hierarchy in the next version.
[Click on image for larger view.]
|Figure 2. The Call Hierarchy (available only in C#) allows you to explore and navigate your application from the perspective of dependencies -- what other code a particular method calls and what code it's called by. Double-clicking the call site navigates to that code. |
Kathleen is a consultant, author, trainer and speaker. She’s been a Microsoft MVP for 10 years and is an active member of the INETA Speaker’s Bureau where she receives high marks for her talks. She wrote "Code Generation in Microsoft .NET" (Apress) and often speaks at industry conferences and local user groups around the U.S. Kathleen is the founder and principal of GenDotNet and continues to research code generation and metadata as well as leveraging new technologies springing forth in .NET 3.5. Her passion is helping programmers be smarter in how they develop and consume the range of new technologies, but at the end of the day, she’s a coder writing applications just like you. Reach her at email@example.com.