Dynamically change FontFamily in rdlc report RRS feed

  • Question

  • I would like to change FontFamily according to text lenght - swap between normal and condensed font within column with constant width.

    I tried to write code for measure string in Report Properties - Code like this:

    Public Function getTextWidth(ByVal text As String, ByVal fntFamName As String, byVal fntSiz As Single) As Single
        Dim fntFam As New System.Drawing.FontFamily(fntFamName)
        Dim fnt As New System.Drawing.Font(fntFam,fntSiz)
        Dim bmp As New System.Drawing.Bitmap(1, 1)
        Dim graphic As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bmp)
        Dim sirka As Single = graphic.MeasureString(text, fnt).Width
        Return sirka
     End Function

    In Textbox properies Font expression I put a condition but I have no idea about correct format of it:

    =IIF( Code.getTextWidth(Trim(Fields!ns_cpa.Value),Fields!ns_cpa.FontFamily,Fields!ns_cpa.FontSize)>100.0,"NarrowFont",Fields!ns_cpa.FontFamily)

    It doesn't work. I need to compare width of column and width of text value and in cae of wider text to change font to "NarrowFont"

    Can anybody help? Thnx

    Friday, August 3, 2012 12:38 PM

All replies

  • By the way: Finally I realized that I can't get value nor from Fields!ns_cpa.FontFamily nor from Fields!ns_cpa.FontSize and pass them as the parameters to the Code. I don't know why but it is a fact.

    I work with local report .rdlc under Visual Studio 2010.

    • Edited by vrasko Tuesday, August 7, 2012 12:20 PM
    Tuesday, August 7, 2012 12:19 PM