Adding Controls to a Windows Form

There are limits to the types of controls you can add to toolbars and menus. Often you might want to provide a user interface where end users can perform multiple tasks, such as selecting an entry from a drop-down list, typing data into a text box, and then clicking a button. Using VBA, you can do this by adding ActiveX controls to a UserForm and then writing code behind the controls. VSTO enables you to use

Windows Forms and a large variety of controls, called Windows Forms controls. In this section, you'll design a Windows Form to collect data from the end user and then add the data to the document.

Using the Logo application we used in the section entitled, "Creating Menus and Menu Items," let's write code to display a Windows Form that enables the end user to select from a variety of logos and insert text to create a letterhead. First, we add a table to the header and then apply formatting. The logo and text will be inserted into these table cells when the user clicks the Insert button on the dialog box.

1. On the View menu, point to Microsoft Office View Word, and click Headers and Footers.

2. On the Header and Footer toolbar, click Page Setup, as shown in Figure 8.9.

Figure 8.9. Opening the Page Setup dialog box from within a header

3. In the Page Setup dialog box, click the Different First Page check box, as shown in Figure 8.10. This setting allows you to add text and graphics to the header for the first page of your document (the first section in your document); the text and graphics don't appear on subsequent pages.

Figure 8.10. Creating a different first-page header

4. Add a table with two columns to the header.

5. Format the left table cell to be center aligned, as Times New Roman 8 pt.

6. Format the right table cell to be left aligned, as Times New Roman 36 pt.

7. With your cursor in the right table cell, click the Format menu, and then click Paragraph. In the Indents and Spacing dialog box, set Spacing Before to 12. Your table should resemble the one in Figure 8.11.

0 0

Post a comment