Change the font of a textbox by code outside the report RRS feed

  • Question

  • Hi everybody!

    I'm using reporting services with local report.

    Is it possible to change the font of a textbox by code? For example, you can pass the parameters values in an array and then the reportviewer bind its values, how can I pass or set the font of a textbox in the report by code before the report is shown?

    The idea is to give to the user the possibility of choose the Font before the report is shown. The Font would be chosen by a Font Dialog Component.

    Thanks to all,

    Wednesday, October 8, 2008 9:25 AM

All replies

  • Hey Jesús,

    This is pretty easy to do and you are on the right track.

    In the report designer, add parameters for whatever part of the font you want to customize: FontFamily, FontStyle, etc. In the textbox that needs the customizable font, go to the PropertyPane and set the font properties to these parameters

    FontFamily, set to "=Parameters!MyFontFamilyParam.Value" for example

    Then in the code, just set those parameters from a Font object:

            private void OnFontButtonClick(object sender, EventArgs e)  
                FontDialog fd = new FontDialog();  
                Font chosenFont = fd.Font;  
                if (chosenFont != null)  
            private void DisplayReport(Font font)  
                this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] {   
                    new ReportParameter("MyFontFamilyParam", font.Name),  
                    new ReportParameter("MyFontStyleParam", font.Style.ToString()),  
                    new ReportParameter("MyFontSizeParam", font.SizeInPoints.ToString() + "pt")   

    You will find that in the Font object, the Style property contains both FontStyle and FontWeight or'ed together, so to really do this right will require extracting those values out as needed.

    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Proposed as answer by Matt E Greer Wednesday, October 8, 2008 4:06 PM
    Wednesday, October 8, 2008 3:36 PM
  • Thank you! It can be a solution. I thought that it was possible to 'get' the textbox object and configure its properties by code.
    Wednesday, October 8, 2008 3:55 PM