Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1725
Calculating Element Sizes
posted

 

I'm trying to use Documents Reports and seem to be having some basic problems (or just things that I don't understand yet.

For example. I'm trying to set the height of the report header. I've got a header with an image and then n-lines of text. The text can be variable in length and number of lines. What I'd like to be able to do is to use the various "Addxxx" methods and either have the height calculated based on the content or give me some method of getting the resulting height. This does not seem to be available or I'm missing something basic.

I've also got a grid with multiple columns. I want to set the width of the first column based on the widest text in the column cells. Again, I'd like to have the grid figure that out for me similar to what I can have the UltraGrid do for me with autoresize. Instead, I tried the following

 Infragistics.Documents.Report.Text.Style boldStyle = new Infragistics.Documents.Report.Text.Style(
                        new Infragistics.Documents.Graphics.Font("Verdana", 8, Infragistics.Documents.Graphics.FontStyle.Normal),
                        Infragistics.Documents.Graphics.Brushes.Black);

 

//* Since I don't seem to be able to get to the base font from the style I did

Font textFont = new Font(normalStyle.Font.Name, normalStyle.Font.Size, FontStyle.Regular);

//Then, loop over the text and try to get the width

Int32 maxColumnWidth = 0;

Size cellSize;
Size proposedSize = new Size(int.MaxValue, int.MaxValue);
TextFormatFlags flags = TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix; //TextFormatFlags.GlyphOverhangPadding | TextFormatFlags.Left | TextFormatFlags.ExternalLeading | TextFormatFlags.WordBreak;
 foreach ( String thing in _myListOfThings )

{

       String newThing = thing.Replace("<br/>", System.Environment.NewLine);
       cellSize = TextRenderer.MeasureText(newThing, textFont, proposedSize, flags);
        maxColumnWidth = Math.Max(tastableColumnWidth, cellSize.Width); 

 textFont.Dispose();

gridColumn = grid.AddColumn();
gridColumn.Width = new Infragistics.Documents.Report.FixedWidth((float) maxColumnWidth);

 This does calculate something that looks reasonable but when I get the exported PDF result the first column is about 40% wider than what I think I calculated in the above. 

In any case, is there something I'm missing here that would make Reports more usable?

 

Thanks