Is there a way to automatically resize fonts to fit text within a control?
The answer to this question is yes! And we've made it easy by providing a ShrinkToFit property on the TextBox control in Page and Section reports, and on the Label control in Section reports. Set the property to True and ActiveReports takes care of the rest. For information on the ShrinkToFit property, see the Shrink Text to Fit In a Control topic in the User Guide. Here are links to the members in the class library:
- ShrinkToFit (TextBox) Page report
- ShrinkToFit (TextBox) Section report
Things to be aware of when using this property:
- CanGrow and CanShrink property settings
- Vertical text
- MultiLine and WrapMode property settings
CanGrow and CanShrink property settings
When you set both ShrinkToFit and CanGrow or CanShrink to True on a control, any CanGrow or CanShrink property setting is ignored. CanGrow and CanShrink are features that adjust the size of control to fit the text string that it contains. Conversely, ShrinkToFit is a feature that adjusts the size of the font to fill the control. When ShrinkToFit is True, it takes priority over CanGrow and CanShrink settings.
Note: CanGrow and CanShrink properties are only found in Section reports.
Here is an example of these properties in action. First, here is the report at design time. And here is how it looks at run time. Notice that CanGrow only applies when ShrinkToFit is False, and neither property takes effect when the text doesn't exceed the width of the control. Here are links to the Class Library for each of these properties:
- CanGrow (TextBox) Section report
- CanShrink (TextBox) Section report
Vertical text
You can optimize text for vertical rendering in Section reports using the VerticalText property, or in Page reports using the WritingMode property. When you set both ShrinkToFit and VerticalText or WritingMode to True on a control, the ShrinkToFit setting is ignored. The text string in the control displays vertically, but the size of the font is not reduced and the text string may only partially fill the control.
MultiLine and WrapMode property settings
In order to allow the ShrinkToFit feature to work properly, ensure that the WrapMode property is set to NoWrap. If you set the MultiLine and WrapMode properties like the following, the ShrinkToFit feature does not work.
MultiLine Property: False WrapMode Property: WordWrap
With these settings, only one line of text displays in the control, and the text that is sent to the following lines by the WordWrap setting is not displayed in the report, and ShrinkToFit has no effect. Note: MultiLine and WrapMode properties are only found in Section reports.