Using the NotesRichTextStyle class, you can format the content of a Rich Text object. This routine illustrates how to set the font, change the font size, and apply color to text.
How It Works
To format Rich Text objects, a style property is assigned to a NotesRichTextStyle object (such as the font). This style is then applied to the Rich Text object. After it is applied, all subsequent text inserted into the object will contain these applied characteristics. The style changes can be applied prior to any text insertions.
Implementation
Formatting text strings requires a NotesRichTextItem and NotesRichTextStyle object. After they are defined, set the style properties prior to inserting text. The following illustrates an action button that sends an email with three uniquely formatted text strings. Notice that the style properties are set and applied to the Rich Text object (called rtitem) prior to using the appendtext method to insert a text string.
Sub Click(Source As Button) '-------------------------------------------------------- ' Define the objects '-------------------------------------------------------- Dim s As NotesSession Dim w As NotesUIWorkspace Dim db As NotesDatabase Dim doc As NotesDocument Dim PersonName As NotesName Dim rtitem As NotesRichTextItem Dim richStyle As NotesRichTextStyle Set s = New NotesSession Set w = New NotesUIWorkspace Set db = s.CurrentDatabase Set doc = New NotesDocument (db) '-------------------------------------------------------- ' Build the email header '-------------------------------------------------------- Set Person = New NotesName (s.UserName) doc.Form = "Memo" doc.SendTo = Person.Abbreviated doc.Subject = "Sample email with formatted Richtext" '-------------------------------------------------------- ' Create the Rich Text item and style objects '-------------------------------------------------------- Set richStyle = s.CreateRichTextStyle Set rtitem = New NotesRichTextItem(doc, "Body") '-------------------------------------------------------- ' Set Font=courier, Fontsize=14 '-------------------------------------------------------- richStyle.NotesFont = FONT_COURIER richStyle.FontSize = 14 Call rtitem.AppendStyle(richStyle) Call rtitem.AddNewline(1) Call rtitem.AppendText("You are invited to a...") Call rtitem.AddNewline (2) '-------------------------------------------------------- ' Set Fontsize=24, Color = Dark Magenta ' Font is still Courier, Bold and Italic '-------------------------------------------------------- richStyle.NotesColor = COLOR_DARK_MAGENTA richStyle.FontSize = 24 richStyle.Bold = True richStyle.Italic = True Call rtitem.AppendStyle(richStyle) Call rtitem.AppendText("New Years Eve party!") Call rtitem.AddNewline (2) '-------------------------------------------------------- ' Set Font=Roman, Fontsize=14, Color=Blue ' Turn off Italic, Bold is still enabled '-------------------------------------------------------- richStyle.NotesColor = COLOR_BLUE richStyle.NotesFont = FONT_ROMAN richStyle.FontSize = 14 richStyle.Italic = False Call rtitem.AppendStyle(richStyle) Call rtitem.AppendText("See you there!") '-------------------------------------------------------- ' Send the email '-------------------------------------------------------- doc.Send False Msgbox "Sample email has been sent." End Sub
Figure 13.23 illustrates the email generated by this LotusScript code example.
Figure 13.23. Format text in a Rich Text field or object
An Introduction to the Lotus Domino Tool Suite
Getting Started with Designer
Navigating the Domino Designer Workspace
Domino Design Elements
An Introduction to Formula Language
An Introduction to LotusScript
Fundamentals of a Notes Application
Calendar Applications
Collaborative Applications
Reference Library Applications
Workflow Applications
Web Applications
Design Enhancements Using LotusScript
Design Enhancements Using Formula Language
View Enhancements
Sample Agents
Miscellaneous Enhancements and Tips for Domino Databases
Data Management
Security
Application Deployment and Maintenance
Troubleshooting
Appendix A. Online Project Files and Sample Applications
Appendix B. IBM® Lotus® Notes® and Domino®Whats Next?