MS Visual Studio How to modify the width of a tab in RichObject

Microsoft Vistual Studio

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
How to modify the width of a tab in RichObject
September 5, 2021 by Vladislav Yarovoy

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:
1631087512976.png
How it looked in the previous version:

1631087522334.png
In the current version:
1631087532249.png

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.