使用 String.Format 格式化的字符串不显示在打印预览中

发布于 2024-12-18 17:24:29 字数 559 浏览 2 评论 0原文

我正在尝试创建具有相应打印预览的打印功能。由于某种原因,我使用 String.Format 创建的任何字符串都不会显示在打印预览中!使用下面的代码片段作为示例:

Dim strTemp As String
strTemp = String.Format("{0, 210} {1, 75} {2, 51} {3, 200} ",
                        "NAME", "PRICE", "QUANTITY", "DESCRIPTION")
e.Graphics.DrawString("hi" + strTemp,
                      New Font("Courier New", 9, FontStyle.Bold),
                      Brushes.Black, 150, 10)

在此示例中,“hi”将显示在打印预览中,但 strTemp 不会显示。我已经尝试了很多事情 - 使用 ToString 即使它已经是一个字符串,将 String.Format() 调用直接放在 DrawString() 内部,仅举几例。有人能解释一下为什么这不起作用吗?

I'm trying to create a print function with a corresponding print preview. For some reason, any string I create with String.Format will NOT show up on the print preview! Use the code snippet below as an example:

Dim strTemp As String
strTemp = String.Format("{0, 210} {1, 75} {2, 51} {3, 200} ",
                        "NAME", "PRICE", "QUANTITY", "DESCRIPTION")
e.Graphics.DrawString("hi" + strTemp,
                      New Font("Courier New", 9, FontStyle.Bold),
                      Brushes.Black, 150, 10)

In this example, "hi" will display in the print preview, but strTemp will not. I've tried many things - using ToString even though it's already a string, putting the String.Format() call directly inside of DrawString(), just to name a few. Can anybody shed light on why this isn't working?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无力看清 2024-12-25 17:24:29

那里有很多空格 - 文本很可能写在图像边界之外,因此不会显示。

You have lots of spaces there - chances are that the text is written outside the image bounds and therefore not showing up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文