4

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

由于这个问题,我知道如何从文件中加载字体,但我无法在 RDLC 报告中使用它。

4

2 回答 2

1

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

// 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

于 2009-03-17T00:01:49.763 回答
0

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

于 2009-03-10T23:22:59.363 回答