-1
我正在使用PrintDocuemnt类来打印记录。在运行时,我提供了字体大小,但是我在打印纸上得到小尺寸的字母。PrintDocument在打印纸上没有打印正确的字体大小
功能1:其与详细调用CreateCheckFormatForCheckWriter方法对象objTCWLDetailLayout和当前选择的对象
List<Image> StringToPrint=new List<Image>;
Image objInput = objCWLayout.CreateCheckFormatForCheckWriter(objTCWLDetailLayout, objCWPrintCheck);
StringToPrint.Add(objInput);
功能2:哪些调用方法CreateCheckFormatForCheckWriter()
Image objCheckImage1 = null;
Graphics g = this.CreateGraphics(); // edited by jeet - assigned this.CreateGraphics()
g.SmoothingMode = SmoothingMode.AntiAlias;
g.TextRenderingHint = TextRenderingHint.AntiAlias;
Brush P = new SolidBrush(Color.Black);
Pen pen = new Pen(Color.Black);
Draw_Check8_StringCompName(objGlobalRulerbitmapData, g, P, i, objCWPrintCheck.ChkCompanyName);
功能3:调用Draw_Check8_StringCompName()方法
private void Draw_Check8_StringCompName(List<TCWLDetail> objGlobalRulerbitmapData, Graphics g, Brush P, int i, string strVal)
{
try
{
string fontFace = ("Vedana");
int fontSize = 6;
Font drawFont = new Font(fontFace, fontSize);
float XCB = horizontalRuler.ScaleValueToPixel(objGlobalRulerbitmapData[i].FX);
float YCB = verticalRuler.ScaleValueToPixel(objGlobalRulerbitmapData[i].FY);
// float YCB = verticalRuler.ScaleValueToPixel((objGlobalRulerbitmapData[i].FY <=(float) 0.1 ?(float) 0.325 : objGlobalRulerbitmapData[i].FY));
string sTemp = strVal;
g.DrawString(sTemp, drawFont, P, XCB, YCB);
}
catch (Exception ex)
{
CusException cex = new CusException(ex);
cex.Show(MessageBoxIcon.Error);
}
}
最后我们在PrintDocument.StringToPrint上设置图像是List类型集合。
private void PrintDocument_PrintPage(Object sender, PrintPageEventArgs e)
{
try
{ //Set image from StringToPrint collection
e.Graphics.DrawImage(StringToPrint[PageCounter], 6, 12, 816, 1256);
//PageCounter++;
//e.HasMorePages = (PageCounter != StringToPrint.Count);
}
catch (Exception ex)
{
CusException cex = new CusException(ex);
cex.Show(MessageBoxIcon.Error);
}
}
我更新了我使用Graphics.DrawString()的实际代码,参见我的更新代码 –
你可以在设置'drawFont'的行上放置一个断点吗?哪种字体大小传递给构造函数?另外,'i'的价值是什么? – Stefan
FontSize是6,Fontface是“Verdan”.objGlobalRulerbitmapData [i]它是包含data.i的int类型值的集合对象。 –