4 Replies Latest reply: Feb 28, 2018 2:54 PM by Stuart Cuthbertson RSS

    Applying font formatting in PixelPerfect

    Stuart Cuthbertson

      Hi all,


      I have done my best to search for existing content about my question and drawn a blank....


      I am experimenting with PixelPerfect reports. This is the first PixelPerfect report I've worked on; I've read the introductory material available, which doesn't go into masses of detail.


      My current goal is simply to bring in the results of a formula and apply some formatting to it (font and font size). My question, in short, is "I seem to have tried everything but it's not working - what am I missing?"

      Here's all the extra info of what I've done:


      Here's what my template looks like:


      At the top of the Detail band is a panel - ignore that.


      Below the panel is a Rich Text box referencing the 'ValueDollars' formula I've created. As you can see, I've chosen Segoe UI in 20pt as the font for this text box. I've actually chosen this font in multiple places - the main Font property seen to the left in the Property Grid, and also under the 'Formatting Rules' and 'Styles' parts, by clicking the [...] next to (Collection) and going through the dialog windows that come up. I confess I haven't yet fully understood the purpose of the Formatting Rules and Styles stuff, I'm just experimenting.


      I then copied that text box - with all the formatting choices applied - and pasted just below, editing the contents to the word 'test' (not a reference to any Formula, Cell, or any other dynamic reference - just static text). So logically this has the exact same format as the box above it.


      When I preview this report, or when I save, close, and run it as a task, here's what I get:


      The $6.9 million number is the correct number - so the formula is working correctly. However you'll notice the font for the formula boxes is the default Times New Roman, and smaller. Whereas the copied static text box has correctly had Segoe UI 20pt applied.


      I'm sure there's some other configuration property that I'm missing, but darned if I can find it...


      Can anyone help point me in the right direction? Thanks in advance!

        • Re: Applying font formatting in PixelPerfect
          Carlos Silva

          Can you show this ValueDollars formula?

          Maybe if you set your formula like this? : =Text(YourFormula)

            • Re: Applying font formatting in PixelPerfect
              Stuart Cuthbertson

              Thanks for the reply Carlos.


              My ValueDollars formula is as follows:

              text(money(round(sum({$<Year=, [Fiscal Year]=, Month=, [Fiscal Month]=, MonthNum=, [Fiscal Month Num]=, OrderTypeCategory-=$(NoDisposals)>} Value)),'$#,###,##0;($#,###,##0);nil'))

              So I was already trying to coerce the formula result to text; I had originally not been using the text() function, and added it to see if it helped - but it didn't.


              The specifics of the set analysis shouldn't be too relevant here, since I know the number being returned is the right one. I'm using money() inside text() because I do want the results to be shown in US standard currency format, with thousand separators etc. Stripping the formula back to just the sum() function without the outer functions does not make any difference to the resulting font.

                • Re: Applying font formatting in PixelPerfect
                  Daniel Jenkins

                  Hi Stuart,


                  Not sure why you are using a RichText control in the first place. You should use RichText to display RichText formatted strings (where each letter can potentially be a different colour, size, font etc.). You can use a Label control instead and set the font quite easily.


                  Having said that, if you want to stick with RichText, you can use script to format the control.



                  Lets say your RichText control has name richText1


                  You can add C# code in the control's BeforePrint event like this:



                  private void richText1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
                  richText1.Font =  new Font("Segoe UI", 20, FontStyle.Bold);
                  //richText1.Font =  new Font(richText1.Font, FontStyle.Italic);
                  richText1.ForeColor =  Color.Blue;




                  HTH - Daniel.

                    • Re: Applying font formatting in PixelPerfect
                      Stuart Cuthbertson

                      Thank you Daniel. Your comment about labels vs rich text was the clue I needed: the only official mention of these (that I had found) hadn't quite made sense to me.


                      When I tried adding my formula onto a label, it immediately formatted correctly. This will actually work fine in my immediate use-case.


                      In general, I want to be able to use the power of a rich text box as well. You could think of my example above as a reduction to the simplest possible example of the problem - in some situations I will want to mix multiple fonts/sizes in a rich text box and include dynamic values from formulas, for which I think your script approach wouldn't work?


                      Thanks to your comment I've experimented further with how I use the rich text box and have found the root cause of my problem. Writing it here in case it helps someone in the future:


                      Wrong way (that I was doing):

                      1. Drag Rich Text control from the 'Tool Box' pane onto report.
                      2. Drag desired formula from 'Field List' pane over newly-added Rich Text box.


                      Right way:

                      1. Drag Rich Text control from the 'Tool Box' pane onto report.
                      2. Double-click on newly-added Rich Text box, then single-click so you get a regular blinking cursor.
                      3. Drag desired formula from 'Field List' pane over Rich Text box.


                      It seems the wrong way adds the second control as a separate entity bound to the first one somehow - so I had a Rich Text box and a Label in the same place, locked to each other (not two objects overlapping). Rather than the right way which just adds a square-bracketed reference to the formula into the sequence of characters within the text box.


                      (The 'wrong way' still works with a Label control, however.)


                      Perhaps somebody else can give a better explanation than me, but either way, the 'right way' always works so I'll be doing that from now on!