Creating Keyboard Shortcut to TFS Source Control Explorer In Visual Studio

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.

  1. Open Visual Studio
  2. On the Tools menu select options
  3. In the Options dialog expand Environment > KeyboardImage
  4. In the Show commands containing edit box type view.tfs and from the resulting list select View.TfsTeamExplorer.
  5. In the Press shortcut keys edit box enter Ctrl + F8 this will assign that key combination the the command.
  6. Hit the Ok button, now you can easily access the Team Explorer from a keyboard shortcut.
Advertisements

How to clear the Immediate window in Microsoft Visual Studio

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 allHere 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 ;-).

Extension Methods In C#

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.

First:
Create a new Visual Studio Win. forms project called demoExtension, to that project add a class and name it extensions.cls.

Second:
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”.

Third:
Replace the code in extensions.cls with the code below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace demoExtension
{
    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]$"))
                {
                    return true;
                }
                return false;
            }
            return true;
        }
    }
}

Fourth:
In the click event for btnSubmit enter code.

private void btnSubmit_Click(object sender, EventArgs e)
{
     if (txtInput.IsEmailValid())
          txtInput.BackColor = Color.Green;
     else
          txtInput.BackColor = Color.Red;
}

Next:
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 🙂

Setting Up Visual Studio 10 for MASM32 Programming

If you are like me and want the comfort and support that Microsoft’s Visual Studio 10 provides, then you will defiantly want that support in your MASM programming tasks. Visual studio makes this quite easy, with a couple of project property changes you will be on your way to MASM programming bliss.

Steps

  1. Create new Visual C++ Empty Project
  2. Right click on the newly created project and select Build Customizations; select masm option, press ok then save the project.
  3. Go to project properties and select linker->system then change subsystem to Windows (/SUBSYSTEM:CONSOLE)
  4. Download and install masm32 libraries then add them to your linker settings.
  5. Go to linker->Advanced and change Entry Point to main [this is what the linker will look for when mapping the entry point for your app.]
  6. Go to Linker->Input  and add masm32.lib to Additional Dependencies.
  7. Go to Microsoft Macro Assembler->General and add the masm32 libraries.
  8. Download and paste usertype.dat into C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
  9. Go to Visual Studio Options->Text Editor->File Extensions: Type asm in the extension box then select Microsoft Visual  C++ from the list.
  10. Right click on project and select Add->New Item: Select Text File and save with *.asm
  11. Create, run and enjoy your code 🙂

In a future post I will show how to turn this project into a Visual Studio project template.