fastreport 如何根据字数的多少控制字体的大小

项目中用到fastreport 进行套打,由于字符数量的多少不知道,所以设定了字体的大小有时候不能将内容打权,
这时候我们可以根据预先设定的字体,测试 字符数量和全部打印出来时设置的字体大小,然后在代码中对字体
的大小进行控制。

代码块

  private void CompareFontSize(TableCell cell)
    {
      if(cell.Text.Length<=27)
      {  
        cell.Font=ChangeFontSize(cell.Font,9);
      }
      else if(cell.Text.Length<=39)
      {
        cell.Font=ChangeFontSize(cell.Font,8);
      } 
      else if(cell.Text.Length<=54)
      {
        cell.Font=ChangeFontSize(cell.Font,7);
      }  
      else if(cell.Text.Length<=76)
      {
        cell.Font=ChangeFontSize(cell.Font,6);
      }  
      else
      {
        cell.Font=ChangeFontSize(cell.Font,5);
      }  
    }

    private Font ChangeFontSize( Font font, float fontSize )
    {
      if (font != null)
      {
        float currentSize = font.Size;
        if (currentSize != fontSize)
        {
          font = new Font( font.Name, fontSize,font.Style, font.Unit,font.GdiCharSet, font.GdiVerticalFont);
        }
      }
      return font;
    }

猜你喜欢

转载自blog.csdn.net/kongzhonliuxing/article/details/80276528