Tuesday, June 24, 2008

Customizing the Visual Studio Toolbar

When I wrote my last post I hoped to provide a link to a nice explanation of how to customize your Visual Studio Toolbar. I find this is one of the simplest changes you can make to increase your productivity. For example, as a professional developer you probably stopped using the little "cut", "copy" and "paste" icons in the toolbar long ago. Why not get rid of them and replace them with something more useful?

Here is how to do it:
1) Close all instances of Visual Studio except leave one instance open.
2) Right-click anywhere in the toolbar and choose "Customize" at the bottom of the menu.
3) You will then see the "Customize" Dialog Box. Select the "Commands" tab.

4) To remove a command from your current toolbar simply click on the icon in your current toolbar and drag it onto the "Customize" Dialog Box. Go ahead, be adventurous and get rid of cut, copy and paste forever. You can remove unused menu items as well as generally rearrange the position of items by simply dragging them to your desired location.
5) To add a new item to the toolbar simply find the item within the "Customize" dialog box's list of commands and drag it into the desired position in your toolbar. You can even drag the item into menus if you desire. For example, in this screenshot I am ready to drag the "Selection Comment" button onto the toolbar.
6) This step is the productivity booster. Once you have all of your items just where you want them you can assign custom shortcut keys to them. With the "Customize" dialog box still open, select an item in your toolbar and right-click on it. Now you can alter its "name" to be anything you want. In this example I changed the name of the "Selection Comment" button to "&c". Using the ampersand before the letter "c" allows me to click this button by typing alt+c while I am programming. Occassionally, when you do too much customization you will create shortcut conflicts. For example, in my setup I have added a build button to my toolbar and changed its caption to "&b". This conflicts with the fact that the "Build" menu also has &B assigned as a shortcut. The solution is to right click on the "Build" menu option and remove the "&" from the beginning of the name.

7) You can even add buttons to the toolbar to execute any macros you may have written. Just select "Macros" in the "Categories" list on the left.
8) Close the "Customize" dialog box.
9) Share this tip with your friends.

Be Safe, It's a Jungle Out There...

Sunday, June 22, 2008

These are a few of my favorite things...

Every adventurer has to have tools to survive. These are a few of my favorite shortcuts within the IDE that help me code faster.

These shortcuts all work in C#. I am not certain of the VB.NET equivalent.

Tab Tab = Insert Snippet - Get Bill McCarthy's the nice Snippet Editor here

F12 = Go To Definition - Thanks to Jim Zimmerman for teaching me to use this to navigate to CSS style definitions within ASPX control markup.

F8 = Go To Next Task/Error List Item

Ctrl+. = Show the list of context sensitive actions (e.g. Generate Method Stub, Import Namespace, Refactor...). In the screenshot below you see the familiar little red bar under the "S" in "SaveChanges()". Whenever you see that little red bar you can type Ctrl+. and a list of options will appear. Generally, there is just one option so you can type Ctrl+.+Enter and you will have implemented whatever suggestion VS has recommended. If you pair this tip with the F12 = "Go To Definition" tip you can quickly write code to invoke methods, generate the method stub and navigate to the method body. The great thing about the "Generate Method Stub" refactoring implementation is that it generally determines the correct return type as well as all of the parameter types and places the method in the correct class.

Customizing the ToolBar (More on this in anothe post to follow)

A great place to get daily tips is Sara Ford's Blog

I hope that 1 or all of these types can help provide you with more valuable tools in your coding adventures.

Saturday, June 21, 2008

Lambda => Epiphany

I am back! There was a lot of speculation that this adventurer had fallen into a large pit of quick sand or appeared on Survivor. I can neither confirm nor deny that either of those events happened.

Something nearly as drastic did happen however. I converted to C#! It actually was much easier than escaping from quick sand. With my classic ASP, HTML and JavaScript background the jump from using JavaScript to C# was quite natural. Dare I say "easy?" In fact if anyone is on the fence about which .NET language to develop in and you will be writing some JavaScript I cannot encourage you enough to choose C#. You will become a much better JavaScript programmer and you will only have to remember one set of syntax.

With so much scripting involved in modern web pages and that frequency increasing daily it just makes sense to be as strong as you can be in JavaScript. Developing in C# everyday will make that happen. Of course, the fact that Visual Studio 2008 now has JavaScript intellisense and breakpoints makes JavaScript programming MUCH easier. Bless the good folks in the VS IDE Team for making that possible!

Enough about where I've been hiding the past 11 months, let's get to something interesting.

Today, I attended the Sarasota .NET Developers Group's Visual Studio 2008 Launch Event. There were 3 very good presentations. Each got me thinking. I will be writing about several of these thoughts over the coming days (well, nights).

In David Hayden's (a local Sarasota C# MVP) presentation about the new 3.0 language features he mentioned lambda expressions and gave a nice example of how to route event handlers directly to methods and I thought, "That's a great way to save a bunch of useless typing." Because I get paid by the year, not the number of lines of code I am always in favor of typing less code.

So, here's how it works...

As you can see I'm adding the eventhandler to each button's Click event in Page_Load. Notice that I don't even have to write the traditional event handlers (commented out at the bottom). I can just skip that and get right to the fact that I want the event to invoke my own methods, "SaveChanges()" and "CancelChanges()". Since I have gotten in the habit of trying to never write more than 1 line of code in an event handler this works great for my coding style.

Another added benefit to this lambda syntax is that I do not have to write any code in the ASPX page related to stating which event should be associated with each control's Click event.

All of my event handler associations are in the .cs file. This is just one more way to break the presentation layer from the business logic. I believe that in 1 year I won't be doing web pages in ASPX but rather XAML I want to keep as much as I can out of the ASPX pages.