在Visual Studio 2005中,我如何从文件中加载字体并在RDLC报告中使用它?
我知道如何从文件中加载字体,感谢这个问题:此处,但我无法在RDLC报告中使用它。
我知道如何从文件中加载字体,感谢这个问题:此处,但我无法在RDLC报告中使用它。
如果你只需要字体用于一个或两个标题,或者用于条形码列,那么你可以在数据集上创建一个图像类型的列,并将图像预先制作为文本到位图。
// 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;
}
}
}
你也可以创建一个自定义报表项来替换默认的文本框等,但从所有的经验来看,这些都是非常麻烦的。
看起来唯一的方法是在Windows上安装字体,然后像系统中的任何其他可用字体一样使用它。