【问题标题】:How to load Font from file on a RDLC report?如何从 RDLC 报告的文件中加载字体?
【发布时间】:2010-10-07 21:37:06
【问题描述】:

在 Visual Studio 2005 中,如何从文件加载字体并将其用于 RDLC 报告?

感谢this 问题,我知道如何从文件中加载字体,但我无法在 RDLC 报告中使用它。

【问题讨论】:

    标签: visual-studio-2005 .net-2.0 fonts rdlc


    【解决方案1】:

    似乎唯一的方法是在 windows 上安装字体并像系统上可用的任何其他字体一样使用它。

    【讨论】:

      【解决方案2】:

      如果您只需要一个或两个标题或条形码列的字体,那么您可以在图像类型的数据集上创建一个列,并将图像作为文本预先制作为位图

      // From dreaming in code
      /// <summary>
      /// Function for converting text to a Bitmap object
      /// </summary>
      /// <param name="width">Width of the image</param>
      /// <param name="height">Height of the image</param>
      /// <param name="str">String to be converted</param>
      /// <param name="textColor">Color we want the text</param>
      /// <param name="recColor">Color we want the background</param>
      /// <param name="f">Name of the font we want used</param>
      /// <returns></returns>
      /// <remarks></remarks>
      public Bitmap ConvertTextToBitmap(ref int width, ref int height, ref string str, ref Color textColor, ref Brush recColor, ref string fontName)
      {
          using (Bitmap bmp = new Bitmap(width, height)) 
          {
              using (Graphics gfx = Graphics.FromImage((Image)bmp)) 
              {
                  gfx.SmoothingMode = SmoothingMode.AntiAlias;
                  Font font = new Font(fontName, 11, FontStyle.Regular, GraphicsUnit.Pixel);
                  gfx.FillRectangle(Brushes.Transparent, new Rectangle(0, 0, bmp.Width, bmp.Height));
                  gfx.FillRectangle(recColor, 0, 0, width, height);
                  gfx.DrawString(str, font, new SolidBrush(textColor), 2, 3);
                  bmp.Save(Application.StartupPath + "\\" + str + ".bmp", ImageFormat.Bmp);
                  return bmp;
              }
          }
      }
      

      您还可以制作自定义报告项来替换默认文本框等,但从所有经验来看,这些都是一个很大的 PITA

      【讨论】:

      • 我可以在报表上动态执行此操作吗?
      • 我不能在磁盘上写,那就不行了... :-(
      • 使用此示例,您必须在启动 RDLC 之前在数据集中预先制作图像。您不需要写入磁盘,这只是糟糕的示例代码抱歉。如果您想在报表中动态地执行此操作,则需要制作自定义报表项或自定义报表呈现器,两者都很难
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-06
      • 1970-01-01
      相关资源
      最近更新 更多