Access text boxes are pretty handy to use as far as inputting data for storage and display. With the capability to specify scroll bars and use the CanGrow/CanShrink properties, they're as versatile as most other DBMSs in the market today. However, with the growing technology of Windows and developers giving users more WYSIWYG (“what you see is what you get”), the plain ol' text box just doesn't cut it sometimes.
The ActiveX Microsoft Rich Textbox control gives you another tool for enriching your interfaces. With the Rich Textbox control, you can
The WindowsCommonControlsRichText form has an example that allows users to load and save text from a Rich Textbox control. You also can select text inside the control and then toggle the text to be boldface or italic, and choose the alignment you desire. The last thing you can do with this example is to print the text.
Figure 14.17 shows the WindowsCommonControlsRichText form as a subform on WindowsCommonControls.
The code behind each button on the WindowsCommonControlsRichText form is examined in a moment. First, look at some of the properties of the Rich Textbox control that affect the selected text (see Table 14.4).
Property | Description |
---|---|
SelAlignment[*] | Affects the alignment of the selected text. Possibilities are 0 - Left, 1 - Right, and 2 - Center. Also returns the current setting. |
SelBold[*] | Boldfaces or unbolds text based on the value set (0 - Un-Bold or 1 - Bold). Also returns the current setting. |
SelBullet | Sets paragraphs with bullets, indented by whatever the BulletIndent property is set (0 - No Bullets, 1 - Bullets, or Null - Spans more than one paragraph). Also returns the current setting. |
SelColor[*] | Sets the foreground color of text. May be set by using RGB() or the CommonDialog ActiveX control. Also returns the current setting. |
SelFontName | Specifies the font name for the selected text. Can be set by supplying the name or by using the CommonDialog ActiveX control. Also returns the current setting. |
SelFontSize | Specifies the font size for the selected text. Can be set by supplying the size or by using the CommonDialog ActiveX control. Also returns the current setting. |
SelHangingIndent | Used with SelIndent and SelRightIndent to specify the indentation for a paragraph. Also returns the current setting. |
SelIndent | Used with SelHangingIndent and SelRightIndent to specify the indentation for a paragraph. Also returns the current setting. |
SelItalic[*] | Applies or removes italics in text based on the value set (0 - Unset Italics, 1 - Italics). Also returns the current setting. |
SelLength | Set the amount of text to currently select. Used with SelStart. Also returns the current setting. |
SelRightIndent | Used with SelHangingIndent and SelIndent to specify the indentation for a paragraph. Also returns the current setting. |
SelRTF | Converts the selected text into Rich Text Format. |
SelStart | Specifies the starting position of the selected text. If no code is selected, it gives the position of the cursor. |
SelStrikethru | Applies or removes strikethrough text based on the value set (0 - Unset Strikethru or 1 - Strikethru). Also returns the current setting. |
SelText | Returns the currently selected text. |
SelUnderline[*] | Applies or removes underline text based on the value set (0 - Unset Underline, or 1 - Underline). Also returns the current setting. |
[*] Example found on the WindowsCommonControlsRichText form
As with other properties, you can tell what the current status of each property is by simply viewing the property. On the WindowsCommonControlsRichText form, the cmdBold and cmdItalics buttons toggle the SelBold and SelItalic properties. Listings 14.8 and 14.9 show the code for each button. First, Listing 14.8 shows the cmdBold_Click code.
Listing 14.9 shows the cmdItalics OnClick code.
Setting the alignment takes a little bit more work, but not much. Because the SelAlignment property takes one of three values, a combo box has been set up on the form to reflect these choices. Here is the RowSource for the cboAlignment combo box, which is a Value list:
0;"Left";1;"Right";2;"Center"
The AfterUpdate event contains the event procedure that actually sets the SelAlignment property (see Listing 14.10).
The last two pieces of code to look at for the Rich Textbox control are for loading from and saving to files, using the text in the control. Listing 14.11 shows the cmdLoad_Click subroutine, which is attached to the OnClick event of the cmdLoad command button.
This routine uses a CommonDialog control, using the ShowOpen method, to get the file to open. The routine to save the text, shown in Listing 14.12, is similar to the load routine and can be found on the OnClick event of the cmdSave command button.
You can use the Microsoft Rich Textbox control in a lot more tasks just by expanding on the WindowsCommonControlsRichText form.
3.22.27.45