How to determine text width of a TextObject at runtime
If at design time, I place a text object onto the surface, and set its anchor to Top and Right, and set HorzAlign to Right, and AutoWidth to True, after previewing the report the text will appear right-justified as expected with correct width.
Performing these steps at runtime is not giving the same results however, and the text appears far off to the right off the page.
If I cannot use AutoWidth on right-justified text at runtime, is there a way to calculate the width of the text?
I know about Graphics.MeasureString, but I don't see a reference to a Graphics object on the report to do such a calculation.
Help is appreciated!
Performing these steps at runtime is not giving the same results however, and the text appears far off to the right off the page.
If I cannot use AutoWidth on right-justified text at runtime, is there a way to calculate the width of the text?
I know about Graphics.MeasureString, but I don't see a reference to a Graphics object on the report to do such a calculation.
Help is appreciated!
private void button4_Click(object sender, EventArgs e)
{
Report report = new Report();
report.CreateUniqueName();
FastNameCreator nameCreator = new FastNameCreator(report.AllObjects);
ReportPage page = new ReportPage();
report.Pages.Add(page);
nameCreator.CreateUniqueName(page);
page.Overlay = new OverlayBand();
page.Overlay.Height = Units.Inches * 10.0f;
TextObject textObject = new TextObject();
textObject.Parent = page.Overlay;
nameCreator.CreateUniqueName(textObject);
textObject.Top = Units.Inches * 1.0f;
textObject.Height = Units.Inches * 0.5f;
textObject.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right;
textObject.AutoWidth = true;
textObject.Left = Units.Inches * 3.0f;
textObject.HorzAlign = HorzAlign.Right;
textObject.Text = "Hello World";
report.Show();
}