How Can I Set The Font Size of a Rich Text Box Programmatically?
Primary Software: LabVIEW Development Systems>>LabVIEW Base Package
Primary Software Version: 8.0
Primary Software Fixed Version: N/A
Secondary Software: N/A
Problem: I created a Rich Text Box control, a .NET object, and I would like to set its font size programmatically. I tried by using property "Size" of the property "Font" of the Rich Text box but it is read-only. How can I accomplish this?
Solution: To set the font size of a Rich Text Box programmatically, you need to follow these steps:
- Place a Rich Text Box control (found in Controls palette».NET & ActiveX) on the Front Panel.
- Create a Font property node for the Rich Text Box by right-clicking it and selecting Create»Property for System.Windows.Forms.Rich Text Box class and then select Font.
- Connect the Rich Text Box to the reference input of this property node.
- Place a property node (found in Functions palette»Application Control) and connect to its reference input the output of the property node that you created at step 2.
- Select property FontFamily.
- Place a constructor node (found in Functions palette»Connectivity».NET) on the Block Diagram.
- In the Select .NET Constructor dialog box, select Assembly System.Drawing (2.0.0.0), Object System.Drawing.Font and Constructor Font(FontFamily family, Single emSize).
- Connect to family input of the Font object the output of the FontFamily property node that you created in step 4.
- Connect to emSize input the desired value for the font size of the Rich Text Box (for example, through a control).
- Connect new reference output of the Font object to the Font property of the Rich Text Box object (that you can create as described in step 2).
The attached VI implements all these steps. For test purposes, a sequence structure to set the text of the Rich Text Box and to read its size property is present.
Related Links: MSDN page for Rich Text Box class
Attachments:
Rich_Text_Box_font_size.vi
Report Date: 11/12/2008
Last Updated: 11/13/2008
Document ID: 4RB9AEHL