
Create a Command Bar in Word 2003 #84
Chapter 11, Visual Studio Tools for Office
|
369
HACK
Create the Command Bar
When the wizard has completed, you will be placed into the main code file
named ThisDocument.cs. Most of your code will execute when a user cre-
ates a new instance of your document. This event is handled by the follow-
ing method:
protected void ThisDocument_New( )
{
}
At this point, you are going to need to create some class-level variables to
work with as you build your command bar. The main class is
OfficeCodeBehind, so your code should look something like this:
public class OfficeCodeBehind
{
private object oMissing = System.Reflection.Missing.Value;
private Office.CommandBar CBar;
private Office.CommandBarComboBox CBarComboBox;
private Office.CommandBarButton CBarButton;
// ...
}
Next, you will need to write some code to create the different user interface
elements that you plan to place on the command bar. In this example, you
will need a combo listbox and a button. (You may need to change the connec-
tion string, highlighted in bold, to suit your SQL Server or MSDE installation.)
Figure 11-2. Microsoft Office Project Wizard