One of the most hated actions that a programmer has to do is having to click on anything in the IDE. One way to avoid this needless waste of movement is to create keyboard shortcuts. These shortcuts allow the programmer to keep her hands on the keyboard where it belongs.
Keyboard shortcuts are created by mapping a Visual Studio IDE Command to a key sequence, this is achieved with the following steps.
- Open Visual Studio
- On the Tools menu select options
- In the Options dialog expand Environment > Keyboard
- In the Show commands containing edit box type view.tfs and from the resulting list select View.TfsTeamExplorer.
- In the Press shortcut keys edit box enter Ctrl + F8 this will assign that key combination the the command.
- Hit the Ok button, now you can easily access the Team Explorer from a keyboard shortcut.
If you have used Visual Studio x for any length of time you would have become familiar with the immediate window, this window allows you to quickly evaluate expressions when a break point is hit. You would have equally been frustrated with having to right click in the window to then clicking clear all. Here is a neat trick that will allow you to clear the command window, just type >cls then hit return and surprise the window will be cleared ;-).
C# extension methods allow developers to extend the capability of controls by providing a method which associates itself with the particular control; and provides functionality not built into that control. We can view extension methods as a kind of decorator or dependency injection depending on your inclination. Even though extension methods have been around a while now I rarely see use of it in the code produced by my colleagues even though it would greatly improve readability.
Lets see how we can go about creating an extension method for a popular UI control in Visual Studio the textbox.
Create a new Visual Studio Win. forms project called demoExtension, to that project add a class and name it extensions.cls.
Rename Form1 -> frmDemo and drag a Textbox and Button control unto the form, rename them txtInput and btnSubmit respectively. Set the btnSubmit.Text property to “Submit”.
Replace the code in extensions.cls with the code below.
static class extensions
static public bool IsEmailValid(this TextBox emailTextBox)
if (emailTextBox.Text.Length > 0)
if (System.Text.RegularExpressions.Regex.IsMatch(emailTextBox.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
In the click event for btnSubmit enter code.
private void btnSubmit_Click(object sender, EventArgs e)
txtInput.BackColor = Color.Green;
txtInput.BackColor = Color.Red;
Run the application and enter a malformed email address then hit the submit button.
Retype the email using correct standard then hit submit.
Have fun coding 🙂