【问题标题】:XGraphics Draw String from end of stringXGraphics 从字符串末尾绘制字符串
【发布时间】:2019-04-12 11:09:49
【问题描述】:

我正在像这样在彼此之上绘制两个字符串:

gfx.DrawString("Complete Total (Ex VAT) £" + string.Format("{0:0.00}", totalCompletePrice), new XFont(roboto, 10 * 4, XFontStyle.Regular), XBrushes.Black, new XPoint(2445, 2225));
gfx.DrawString(header + " Total (Ex VAT) £" + string.Format("{0:0.00}", totalCompletePrice), new XFont(roboto, 10 * 4, XFontStyle.Regular), XBrushes.Black, new XPoint(2445, 2295));

但我的问题是它们不符合文档的结尾。我想不出一种从头开始绘制这些字符串的方法。所以 1,000.55 英镑总是相互对齐。

例子:

This is a really long header total £999.99
          Complete Total (Ex VAT) £9999.99

我想得到它,以便价格彼此一致。有没有办法指定字符串放置的结束坐标并将其向后绘制?所以它从字符串的末尾开始并从该点绘制其余部分。我尝试了测量字符串功能,但它似乎无法正常工作。

我试过End X co-ord - text length,但没有正确对齐。

【问题讨论】:

    标签: c# wpf pdfsharp


    【解决方案1】:

    尝试使用XStringFormat 参数并指定例如XGraphics.DrawString 的变体XStringFormats.TopRight 或其他右对齐选项。

    您也可以使用XTextFormatter 类。可在此处找到显示右对齐文本的演示:
    http://pdfsharp.net/wiki/TextLayout-sample.ashx

    【讨论】:

    • 它们还没有实现。
    • 在快速浏览源代码后我可以看出,它们是在 WPF 构建版本 1.50 中实现的。其他版本我暂时没查。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    相关资源
    最近更新 更多