How to modify the width of a tab in RichObject

2021-09-05

Some users prefer to create tables by adjusting the tab width, or they want to create a table in a format that does not support them.

In previous versions of FastReport .NET, RichObject offered the function to modify the width of a tab in a line, but all their sizes after the first tab were the same. This has been fixed in the current version and now you can set the size for each tab character.

New property for TextObject TabPositions allows you to set the width of a tab. It is used when converting RichObject. Now you can control the width of tab characters in two ways:

– to set from the code the width of individual tab characters for each line of the TextObject;
– by uploading the finished document into RichObject.

The function to edit this property in the designer is temporarily unavailable. If there are more tab characters than widths, the tab size will be normal, and if there will be more values than tabs, the excess values of width will not be applied.

An example of a text with different tab widths

Original RTF document:

Adjusting the tab width in Word

How it looked in the previous version:

Different tab widths in the previous preview window

In the current version:

Different tab widths in the preview window of this version

Customizing tab width from the code:

 //create instance of class Report
 Report report = new Report();
 //create report page
 ReportPage pageBase = new ReportPage();
 //create data band
 DataBand dataBand = new DataBand();
 //create text object
 TextObject textObject = new TextObject();
 //set the text value
 textObject.Text = "1\t2\t3\t4";
 //set width for every symbol tab in centimeters
 textObject.TabPositions = new FloatCollection() { Units.Centimeters * 2.5f, Units.Centimeters * 3.5f, Units.Centimeters * 5 };
 //add the text object to data band
 textObject.Parent = dataBand;
 //set generated name
 textObject.CreateUniqueName();
 //set the text object bounds
 textObject.Bounds = new RectangleF(0, 0, Units.Centimeters * 15, Units.Centimeters * 0.5F);
 //create one more text object
 TextObject textObject2 = new TextObject();
 textObject2.Text = "5\t6\t7\t8";
 textObject2.TabPositions = new FloatCollection() { Units.Centimeters * 2.5f, Units.Centimeters * 3.5f, Units.Centimeters * 5 };
 textObject2.Parent = dataBand;
 textObject2.CreateUniqueName();
 textObject2.Bounds = new RectangleF(0, Units.Centimeters * 1, Units.Centimeters * 15, Units.Centimeters * 0.5F);
 //create one more text object
 TextObject textObject3 = new TextObject();
 textObject3.Text = "9\t10\t11\t12";
 textObject3.TabPositions = new FloatCollection() { Units.Centimeters * 2.5f, Units.Centimeters * 3.5f, Units.Centimeters * 5 };
 textObject3.Parent = dataBand;
 textObject3.CreateUniqueName();
 textObject3.Bounds = new RectangleF(0, Units.Centimeters * 2, Units.Centimeters * 15, Units.Centimeters * 0.5F);
 //add the band to band collection
 pageBase.Bands.Add(dataBand);
 //add created page to report page collection
 report.Pages.Add(pageBase);
 //show report
 report.Show();

Thus, you can turn RichObject and TextObject into an alternative to the Table object with the help of new improvements.

November 20, 2024

Localization and Language Switching in FastReport VCL

FastReport VCL supports 40 languages for interface localization and allows you to change the language on the fly through menus or code, without recompilation.
November 01, 2024

New Features of the FastReport VCL Editor

We are considering new features of the report editor: extension lines, highlighting of intersecting objects, updated report and data trees.
October 30, 2024

Using Styles When Creating Reports in FastReport VCL

The article discusses one of the new features of FastReport VCL — the use of styles and style sheets.
Fast Reports
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 66 Canal Center Plaza, Ste 505, Alexandria, VA 22314

© 1998-2024 Fast Reports Inc.