Datasheet
58
❘
CHAPTER 1 VISUAL STUDIO 2010
Recording and Using Macros in Visual Studio 2010
Visual Studio macros are part of the environment and are available to any language. Macro options are
accessible from the Tools ➪ Macros menu, as shown in Figure 1 - 38. The concept of macros is simple: Record a
series of keystrokes and/or menu actions, and then play them back by pressing a certain keystroke combination.
FIGURE 1 - 38
For example, suppose that one particular function call with a complex set of arguments is constantly being
called on in code, and the function call usually looks the same except for minor variations in the arguments.
The keystrokes to code the function call could be recorded and played back as necessary, which would insert
code to call the function, which could then be modifi ed as necessary.
Macros can be far more complex than this, containing logic as well as keystrokes. The macro capabilities of Visual
Studio are so comprehensive that macros have their own IDE (accessed via Tools
➪ Macros ➪ Macros IDE).
Macros can also be developed from scratch in this environment, but more commonly they are recorded
using the Record Temporary Macro option on the Macros menu and then renamed and modifi ed in the
development environment. Here is an example of recording and modifying a macro:
1. Start a new Windows Application project.
2. In the new project, add a button to Form1, which was created with the project.
3. Double - click the button to get to its Click event routine.
4. Select Tools ➪ Macros ➪ Record Temporary Macro. A small toolbar (see Figure 1 - 39)
will appear on top of the IDE with buttons to control the recording of a macro (Pause,
Stop, and Cancel).
5. Press Enter and then type the following line of code:
TextBox1.Text = “Macro Test”
6. Press Enter again.
FIGURE 1 - 39
CH001.indd 58CH001.indd 58 4/5/10 11:57:04 AM4/5/10 11:57:04 AM