Skip to Main Content
Visual Studio Hacks
book

Visual Studio Hacks

by James Avery
March 2005
Intermediate to advanced content levelIntermediate to advanced
304 pages
19h 23m
English
O'Reilly Media, Inc.
Content preview from Visual Studio Hacks
372
|
Chapter 11, Visual Studio Tools for Office
#84 Create a Command Bar in Word 2003
HACK
Now that the method to create the command bar is complete, you will need
to call the method to initialize the command bar’s creation when a new doc-
ument is created:
protected void ThisDocument_New( )
{
SetupCommandBar( );
}
Now, test your new command bar by executing the application. Visual Stu-
dio should start an instance of Word, create a new document from your
blank template, and finally raise the
ThisDocument_New event, which will cre-
ate your command bar as shown in Figure 11-3.
Handle the Command Bar Events
Now that you have a command bar in Word, you need to listen for the
events that the command bar raises. In this section, you will learn how to
wire up the command bar events to your custom code.
The first order of business is to create a class-level delegate for the events
you want to handle:
public class OfficeCodeBehind
{
private Office._CommandBarButtonEvents_ClickEventHandler
CBarButtonEvent;
...
Second, you will need to create a method containing the code you want to
run when the command bar raises the event. In this code, you will be taking
the combo box selection and looking up the customer record to type the
address into the Word document:
private void CBarButton_Click(
Office.CommandBarButton btn,
Figure 11-3. Command bar in Word
Create a Command Bar in Word 2003 #84
Chapter 11, Visual Studio Tools ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Microsoft Visual Studio 2015 Unleashed, Third Edition

Microsoft Visual Studio 2015 Unleashed, Third Edition

Mike Snell, Lars Powers
.Net Framework Essentials

.Net Framework Essentials

Thuan L. Thai, Hoang Lam
C# 5.0 Unleashed

C# 5.0 Unleashed

Bart De Smet
Programming .NET Security

Programming .NET Security

Adam Freeman, Allen Jones

Publisher Resources

ISBN: 0596008473Errata Page