$BlogRSDURL$>
General .NET
General .NET
Tuesday, March 30, 2004
Demo better with the toolbox and task list
Two quick simple techniques for people who need to demo code (as I wait for the traffic in front of my house to recede before getting to work).
Oftentimes, you want to demo some code quickly to people and don't want to type it all in. The Toolbox window is very handy for this. Highlight a bunch of code and drag and drop it to the Toolbox window (View->Toolbox). On my machine I generally put this in the General tab on the Toolbox, but you can put it in the User controls tab too. Now when you are demo'ing and need some quick code, just drag and drop it from the Toolbox where you had it previously stored.
Another cool demo tip I've picked up here, is to use the task list. The task list in C# will show you comments for tokens you specify. So lets say you want to demo some feature in File1.cs line 30 and then in File2.cs at line 40. You can navigate back and forth easily using the task list.
Go to Tools->Options->Environment->Task List and type in “Demo” in the Name textbox. Click Add.
Now go to those files locations you want to demo with and add some comments prefixed with Demo like “//DEMO:Show rapid prototyping here”.
Open your task list and right click on your description pane - make sure the Show Tasks option is selected as “All” or “Comments”.
You should now see the task list automatically populate with your comment. Now when doing a demo, you can just open the task list and click to that code block that you want to show.
Now to fight the traffic...
Demo better with the toolbox and task list
Two quick simple techniques for people who need to demo code (as I wait for the traffic in front of my house to recede before getting to work).
Oftentimes, you want to demo some code quickly to people and don't want to type it all in. The Toolbox window is very handy for this. Highlight a bunch of code and drag and drop it to the Toolbox window (View->Toolbox). On my machine I generally put this in the General tab on the Toolbox, but you can put it in the User controls tab too. Now when you are demo'ing and need some quick code, just drag and drop it from the Toolbox where you had it previously stored.
Another cool demo tip I've picked up here, is to use the task list. The task list in C# will show you comments for tokens you specify. So lets say you want to demo some feature in File1.cs line 30 and then in File2.cs at line 40. You can navigate back and forth easily using the task list.
Go to Tools->Options->Environment->Task List and type in “Demo” in the Name textbox. Click Add.
Now go to those files locations you want to demo with and add some comments prefixed with Demo like “//DEMO:Show rapid prototyping here”.
Open your task list and right click on your description pane - make sure the Show Tasks option is selected as “All” or “Comments”.
You should now see the task list automatically populate with your comment. Now when doing a demo, you can just open the task list and click to that code block that you want to show.
Now to fight the traffic...
View exception information with $exception
Every now and then a feature gets put into the product that just gives you this tickle of excitement every time you think about it. $exception I find is one of those features.
Ok - so what scenario would I use it in? Lets say you're writing some managed code. You're debugging your merry way through the code when voilà, it crashes. Sigh. You see the little error dialog with additional information but to explore your code you have to dismiss it. As you go through your code, you wonder what that message said again? So you write a try catch and repeat the process.
Well, in Everett the debugger team put in a little feature called $exception. The next time you crash in C# or J# go ahead and dismiss the dialog. Open the locals window and take a peek at $exception there (chills are setting in right now). Expand it and you can see all the delightful things inside the Exception object - Messages, Stacktrace, Inner Exception etc - everything you would have gotten had you put a try catch around the code and caught the exception object. Is that cool or what?
Exception information in the Object browser
(Find out what exceptions methods throw)
One of the complaints we received from VS7 was that you couldnt tell the exceptions that a particular method could throw. We scratched our heads thinking of ways to do this, as the xml docs did contain this informattion about the class libraries. Ideally we would have liked to have put this information into intellisense, but this request came up after we had done our coding for the milestone. The thing that pushed us off the edge was a usability test we saw, where a guy remarked how painful it was not to have that information.
We ended up adding this information to the object browser. To view it, try something like - Open Object Browser. Open System.IO.File and select the Open method in the right pane. At the bottom of the Object Browsers information pane (where they have method signatures and summary etc), scroll down and you'll see the Exceptions header which should list the exceptions the method can throw.
Addendum #1: This is C#/J# only.
Addendum#2: If you create a dll and put its xml comments file next to it and then view it through the Object browser in a C# project, you should see this for your exceptions too. The equivalent xml tags should be something of the sort:
is less than zero. -or- is greater than .
Keyboard shortcuts
I'm a keyboard shortcut junkie. I love keyboard shortcuts for tasks. I've been known when speaking to devs to say stuff like “Ctrl+alt+l, Select foo.cpp, Ctrl+alt_w+1...no, hit Ctrl+alt...” instead of “ Open the solution explorer, select Foo.cpp, open a watch window...”. A while ago I saw a post where Jason Mauss asked for the keyboard shortcuts to VS.
These are online on MSDN at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxurfvisualstudio70defaultshortcutkeys.asp
Or you can see them in VS 2003 documentation at: ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vsintro7/html/vxurfvisualstudio70defaultshortcutkeys.htm
However, there are some that I find so useful that I thought I would call them out here (note I tend to use the Visual Studio developer profile in Everett. You can change this from Help->Show Start Page and then pick the My Profile tab):
Word wrap. I hate scrolling across the screen to see a really long line of code. Hit Ctrl+R, Ctrl+R instead. Voila - instant word wrap. Hit it again to unwrap. This also works in the output window.
Copy and then cut the current line of code. Oftentimes, you want to move the current line of code you are working on a couple of lines down. Hit Ctrl+C, C. That copies the current line. Hit Ctrl+L to delete the current line of code. Move your cursor down and hit Ctrl+V. That should paste your original line of code.
After a build failure hit F8. F8 takes you through your errors one by one, and highlights them in the code and puts the message in the status bar at the bottom of VS.
Comment and uncomment code quickly. Select your code. Hit Ctrl+K, Ctrl+C. Automatically commented. Select again. Hit Ctrl+K, Ctrl+U. Uncommented.
Auto formatting. Select your code, or hit Ctrl+A if you are lazy like me. Hit Ctrl+K, Ctrl+F. Code is formatted.
Incremental search. I live by this. Hit Ctrl+I and start typing out the word you want to find in the current file. The IDE then matches the word that you've typed. Hit Ctrl+I repeatedly to find the next occurence of that file. Hit Ctrl+Shift+I to go back.
Get Intellisense. Hit Ctrl+Space in your class etc, and you should get an intellisense dropdown that you can complete on.
Got a cool shortcut that you use frequently? Let me know. Spread the love.
Keyboard shortcuts
I'm a keyboard shortcut junkie. I love keyboard shortcuts for tasks. I've been known when speaking to devs to say stuff like “Ctrl+alt+l, Select foo.cpp, Ctrl+alt_w+1...no, hit Ctrl+alt...” instead of “ Open the solution explorer, select Foo.cpp, open a watch window...”. A while ago I saw a post where Jason Mauss asked for the keyboard shortcuts to VS.
These are online on MSDN at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxurfvisualstudio70defaultshortcutkeys.asp
Or you can see them in VS 2003 documentation at: ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vsintro7/html/vxurfvisualstudio70defaultshortcutkeys.htm
However, there are some that I find so useful that I thought I would call them out here (note I tend to use the Visual Studio developer profile in Everett. You can change this from Help->Show Start Page and then pick the My Profile tab):
Word wrap. I hate scrolling across the screen to see a really long line of code. Hit Ctrl+R, Ctrl+R instead. Voila - instant word wrap. Hit it again to unwrap. This also works in the output window.
Copy and then cut the current line of code. Oftentimes, you want to move the current line of code you are working on a couple of lines down. Hit Ctrl+C, C. That copies the current line. Hit Ctrl+L to delete the current line of code. Move your cursor down and hit Ctrl+V. That should paste your original line of code.
After a build failure hit F8. F8 takes you through your errors one by one, and highlights them in the code and puts the message in the status bar at the bottom of VS.
Comment and uncomment code quickly. Select your code. Hit Ctrl+K, Ctrl+C. Automatically commented. Select again. Hit Ctrl+K, Ctrl+U. Uncommented.
Auto formatting. Select your code, or hit Ctrl+A if you are lazy like me. Hit Ctrl+K, Ctrl+F. Code is formatted.
Incremental search. I live by this. Hit Ctrl+I and start typing out the word you want to find in the current file. The IDE then matches the word that you've typed. Hit Ctrl+I repeatedly to find the next occurence of that file. Hit Ctrl+Shift+I to go back.
Get Intellisense. Hit Ctrl+Space in your class etc, and you should get an intellisense dropdown that you can complete on.
Got a cool shortcut that you use frequently? Let me know. Spread the love.
Implementing interface stubs automatically
In Everett, we added a feature to add interface stubs to your code automatically, when you wanted to derive from an interface. To do this simply type out “:” after your class name, type your interface to derive from and you should see a little tooltip pop up that says “Press TAB to implement stubs for interface Ifoo”. Hit Tab and enjoy VS putting in the stubs for you. If you happen to delete the interface and retype a newer one, you might not see the tooltip again. To get it, erase all the way to the “:”. Enjoy...
Quick way to open files in Visual Studio IDE
In 7.0 and later you can simply and quickly open files by going to the Find combo box in the toolbar, and type
>open c:\goo\bar.cpp
The pathname will even auto-complete as you type! Even the command name (“open“ in this case) will auto-complete. You will probably find other handy commands in there by experimenting.
Archives
03/01/2004 - 04/01/2004
