0

我正在使用 C#.net 和 GDI 打印代码打印到热敏打印机 LIPI LWT 150。但是,我无法更改字体大小。我使用的是 Arial 9pt 和 5pt,但它以默认大小显示。有人对此有任何想法吗?

我正在使用这样的 C# 代码:

 public frmSale()
        {
            InitializeComponent();
            printingDoc.PrintPage += new PrintPageEventHandler(Form_PrintPage);
        }

//initalizing print document
private void PrintSettings()
{

    printingDoc.DefaultPageSettings.Margins = new Margins(3, 3, 3, 3);
    PaperSize pSize = new PaperSize();
    pSize.Width = 275;
    printingDoc.DefaultPageSettings.PaperSize = pSize;

    // Claculating the PageWidth and the PageHeight
    PageHeight = printingDoc.DefaultPageSettings.PaperSize.Height;
    PageWidth = printingDoc.DefaultPageSettings.PaperSize.Width;
    // Claculating the page margins
    LeftMargin = printingDoc.DefaultPageSettings.Margins.Left;
    TopMargin = printingDoc.DefaultPageSettings.Margins.Top;
    RightMargin = printingDoc.DefaultPageSettings.Margins.Right;
    BottomMargin = printingDoc.DefaultPageSettings.Margins.Bottom;
    printAreaWidth = PageWidth - RightMargin - LeftMargin;

}

private void Form_PrintPage(object o, PrintPageEventArgs e)
//Here we Begin All the printing Process... 
{

       PrintSettings();
       CurrentY = (float)printingDoc.DefaultPageSettings.Margins.Top;//0;
       PrintEstHeader(e.Graphics);
        DrawEstGridData(e);

}

//Printing Function
private void PrintEstData(Graphics g, string stringData, StringAlignment alignment, Font fnt, Color clr, bool newLine)//,int starting,int maxWidth)
{
    StringFormat stringFormat = new StringFormat();
    stringFormat.Trimming = StringTrimming.Word;
    stringFormat.FormatFlags = StringFormatFlags.NoWrap |
        StringFormatFlags.LineLimit | StringFormatFlags.NoClip;

    stringFormat.Alignment = alignment;

    RectangleF Rect = new RectangleF((float)LeftMargin, CurrentY,
                      (float)PageWidth - (float)RightMargin - (float)LeftMargin,
                      g.MeasureString(stringData, fnt).Height);

    g.DrawString(stringData, fnt,
       new SolidBrush(clr),
       Rect, stringFormat);

    CurrentY += newLine ? g.MeasureString(stringData, fnt).Height : 0;
 }

private void PrintEstHeader(Graphics g)
{

    PrintEstData(g, "----------------------------------------------", StringAlignment.Near, new Font("Arial", 9), Color.Black, true);//,LeftMargin,printAreaWidth);

    PrintEstData(g, "Estimate" + "    " + "Rate  :" + ncRate.Value.ToString("0.00"), StringAlignment.Near, new Font("Arial", 9, FontStyle.Bold), Color.Black, true);//, LeftMargin, 76);

    PrintEstData(g, "----------------------------------------------", StringAlignment.Near, new Font("Arial", 9), Color.Black, true);//, LeftMargin, printAreaWidth);
    PrintEstData(g,"|ITEM |"+"WEIGHT|"+ "STN WT|"+"M.C. %|"+"Total|", StringAlignment.Near, new Font("Arial", 5), Color.Black, true);//,LeftMargin,42);
    PrintEstData(g, "----------------------------------------------", StringAlignment.Near, new Font("Arial", 9), Color.Black, true);//, LeftMargin, printAreaWidth);
}
4

1 回答 1

0

根据打印机规范,它看起来不支持任意字体,但仅支持两种内置的固定宽度字体。除非您可以将位图打印到打印机或创建用户字符,否则我怀疑您是否能够做的不仅仅是选择字体 A 或字体 B。

于 2009-04-07T11:04:29.807 回答