Windows Forms Controls in Word

By default, VSTO adds Word controls to the document inline with text. This means that the control is placed within the text of a document, and, as the text is repositioned, the control also repositions. For example, if you add text to the beginning of a paragraph that contains an inline control, the control will move with the text, or wrap to the next line, when new text is added.

You can change an inline control into a floating object. This means that the control is placed in a drawing layer that can appear behind or in front of text; it is placed at an absolute position that doesn't change when the text changes.

Figure 8.16 shows five Button controls. Starting with the first paragraph, they are formatted Inline with Text (Button1), Square (Button2), Tight (Button3), Behind Text (Button4), and In Front of text (Button5).

The ■ quick-b rown- £b x-jump s ■ over1 the-lazy do g. -The- qui ck-bro wn-fo x-j ump s ■ o ve r-the ■ 1 azydo g. -The -quick- brown' 'n1 iThe-quick-brown-foH-jumps-over-the-lazy-dQg.-The-quick-brown-foK-

jump s,over-the4azy,dog.-The,quick-brown,fox-jumps-over-the-lazy,dog."The,quick-brown-fox-jumps,over,the' lazy-dog.-The-quick,brown-fox,jumps-over-the-lazydog."The,quick-bro wn- fo x-j ump s-over-the-lazy-dog.il i

The ■ quick-b rown- fo x-jump s - over- the ■ lazy-do g. --The- qui ck-bro wn-fo x-j ump s ■ o ve r-the ■ 1 azydo g. --The -quick- brown-fox-j ump s ■ o v er-the ■ 1 azy- | Button2 1 dog. ■ The ■ quick-b rown- fo x-j ump s ■ o ver ■ the ■ lazy ■ do g. ■ -The ■ qui ck-bro wn-

fo x-j ump s ■ o v er-the ■ 1 azy ■ - dog. ■ The - quick-b rown- fo x-j ump s ■ o ver■ the ■ lazy ■ do g. ■ -The ■ qui ck-bro wn-

fox- jumps-over-the-lazy-dog. -The-qui ck-bro wn-fox-jumps-over-the-lazy-dog. --The-quick-brown-fox- jumps-over-the-lazy dog. If n

The ■ quick-b rown- fo x-jump s - over- the ■ lazy-do g. --The- qui ck-bro wn-fo x-j ump s ■ o ve r-the ■ 1 azy do g. --The -quick- brown-fox-jumps-over-the-lazy |—Qutlon3—I dog.-The-quick-brown-fox-jumps-over-the^azy-dog.-The-quick-

brown- fo x-j ump s ■ o ve r-the ■ L-' 1 azy do g. -Th e ■ quick-br o wn- fo x-j ump s ■ o ver-th e ■ lazy ■ do g. ■ ■ The ■ qui ck-

brown- fo x-j ump s ■ o ve r-the ■ 1 azy do g. ■ The - quick-brown- fo x-j ump s ■ o ver ■ the ■ lazy-do g. ■ -The ■ qui ck-bro wn-fo x-j ump s ■ over- the ■ 1 azydo i i

The ■ quick-b rown- fo x-jump s - over- the • lazy-do g. -The- qui ck-bro wn-fo x-j ump s • o ve r-the • 1 azy do g. -The -quick- brown-fox- jumps-over-the-lazy-dog.- ■JFhiuiijjik^ro wn-fo x-j ump s- over-the -1 azydo g.-The-quick-br o wn-fo x-jump s- over-th e • lazy do g. ■ The ■ qui ck-bro wn-fox-jumps- over-the-lazy-dog.--The-quick-b rown- fo x-j ump s ■ o ver-th e ■ lazy do g. • The ■ qui ck-br o wn- fo x-j ump s ■ o ver ■ the ■ 1 azy- do g. ■ -Th e ■ quick-bro wn- fo x-j ump s ■ o v er-the ■ 1 azy ■ do g. If i i

The-quick-brown-fo^-iumps-over-the-lazv-dQg.-The-quick-brown-fo^-iunipS'Qver-the-lazv-dog.-The-quick-brQwn-fox-jumps-over-the-lazy-dog. ■ Button5 |>ro wn-fo x-jumps-over-the-lazy-do g.--The-quick-bro wn-fo x- jumps-over-the-lazy-dog.-The-quick-brown-fox-jumps-over-the-lazy-dog --The-quick-brown-fox-jumps-over-the-lazy-dog -The-quick-brown-fox-jumps-over-the-lazy-dog.--The-quick-brown-fox-jumps-over-the-lazy-dog.T[

Figure 8.16. Controls on a Word document with various positioning settings

Notice that for Button1, the space between the first line of the paragraph and the second line differs from that of the remaining lines. That is because the control is set as Inline with Text, and the bottom of the control is aligned with the bottom of the text. If you were to increase the height of the control, then the space between the first and second lines would also increase.

Button4 is set to appear behind the text, but it appears behind the text only in design view. When you run the application, the button appears in front of the text, enabling users to click it.

If you add text to the beginning of each paragraph, you'll notice that only Button1 moves and always appears between the words dog and The (it stays inline with the text). For all floating control formats, the control remains stationary and the associated text continues to wrap.

To make a control float within the document, you change the wrapping style of the text so that it has any wrapping style other than In Line with Text.

1. Right-click the control and click Format Control.

2. In the Layout tab of the Format Control dialog box, select Square, as shown in Figure 8.17.

Figure 8.17. Setting the wrapping style for text that surrounds a control

3. Select Other in the Horizontal Alignment section, and then click OK. You could also set the alignment of the control as Right, Center, or Left.

If you click the Advanced button on the Format Control dialog box, you'll see that there are several other settings you can apply to the control, such as additional wrapping styles. You'll also find a Picture Position tab (shown in Figure 8.18), where you can set the control's horizontal and vertical alignment. In this tab you can also specify whether the control will move with text and whether it can overlap another control.

Keep in mind, however, that many of these settings are applicable only to the design-time view of the control. At run time, controls cannot overlap and cannot be placed under text in the document. If this Format Control dialog box looks familiar to you, it is because it is the same dialog box that you use when formatting pictures that are in your document.

Figure 8.18. Using the Picture Position tab of the Format Control dialog box
0 0

Post a comment