g.Graphics.drawstring()在C#中从右到左对齐

时间:2018-12-14 06:43:03

标签: c# asp.net

我正在尝试以完全对齐的方式打印收据。在这里,我需要打印.00完全对齐的值。这是我需要放出来的 Receipt

但是我无法正确对齐所有.00值。

这是我尝试过的代码

float maxwidth = Sendwidth(printCase, e, printFont7);

public static float Sendwidth(List<Case> printCase, PrintPageEventArgs e, Font font)
{
    float maxwidth = 0;
    foreach (var singlecase in printCase)
    {
        foreach (var Iteam in singlecase.IItemList)
        {
            string iteamAmount = ConvertNumericToStringAcordingToCulture(Iteam.IAmount);
            string iteamVat = ConvertNumericToStringAcordingToCulture(Iteam.IVatRate);
            string iteam = iteamAmount + "(" + iteamVat + "%)";
            SizeF amountstringSize = e.Graphics.MeasureString(iteam, font);
            if (maxwidth < amountstringSize.Width)
            {
                maxwidth = amountstringSize.Width;
            }
        }
    }
    return maxwidth;
}

PrintAlingmant(e, iiamount, printFont7, maxwidth, x, y);

public static void PrintAlingmant(PrintPageEventArgs e, string printamount, Font font, float maxwidth, float x, float y)
{
    SizeF amountstringSize = e.Graphics.MeasureString(printamount, font);
    var format = new StringFormat() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Center };
    var rect = new RectangleF(x + 175, y, maxwidth, amountstringSize.Height);;
    e.Graphics.DrawString(printamount,font, Brushes.Black, rect, format);
}

0 个答案:

没有答案