如何在VB.NET中减少打印收据中单词之间的空间 [英] How to reduce space between words in a printed receipt in VB.NET

查看:74
本文介绍了如何在VB.NET中减少打印收据中单词之间的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,当我按下打印按钮时,文本框中的数据将被打印。但是当打印收据时,几个单词在这些单词之间获得更多空间,而将其他单词与其他单词进行比较.... 。

我的意思是从文本框到打印页面获取项目的顺序改变了,就像有些单词在它们之间说的更多空格...



我尝试过:



这是我的打印代码

my problem is when my press the print button the data which is present in textbox will be printed .But when the receipt is printed few words are getting more space in between those the words while comparing other with other words.....
I mean the order of getting items from textbox to print page is changed like some words are talking more spaces in between them...

What I have tried:

this is my code for for printing

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        e.Graphics.DrawString(TextBox1.Text, TextBox1.Font, Brushes.Blue, 100, 100)





这是调用打印的代码



this is the code to call print

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  PrintPreviewDialog1.ShowDialog()





请帮帮我...... urgent 。请

推荐答案

我们看不到发生了什么 - 所以我们甚至不能开始给你一个解决方案。所以,这取决于你。



首先使用调试器来查看TextBox.Text中的确切内容 - 它是单行,是吗?多行,它包含什么文本?

然后看看额外空格的位置:它们在句子的特定位置?或者输出中的特定位置?

是否仅在打印预览时发生?实际的打印输出是什么样的?放大打印输出时会发生什么?间距是否会改变?



我的猜测是它是一张收据打印,因此它的纸张宽度很窄 - 当你在任何边缘计算时,文字会被包裹当你不期待它时,到新线;显示为你没有寻找的额外间距。如果是这样,除了将文本框的大小固定在纸张上的可用空间之外,您无法做任何事情。



但是TBH,只是用文本填充TextBox并打印它可能不是收据的最佳方式 - 您应该考虑对实际打印进行正确格式化 - 很少看到整个文本具有相同大小的文本的收据任何粗体,徽标,小地址细节,甚至是跟踪条形码 - 其中任何一个都不能包含在标准TextBox中。
We can't see what is happening - so we can't even begin to five you a solution. So, it's going to be up to you.

Start by using the debugger to look at exactly what is in the TextBox.Text - is it single line, is it multiline, what text does it contain?
Then look at where the "extra spaces" are: are they in specific places in the sentence? Or specific places in the output?
Does it only happen with print preview? What does the actual printout look like? What happens when you zoom in the printout? Does the spacing change?

My guess is that it's a receipt print so it has a narrow paper width - and when you figure in any margins the text gets "wrapped" to new lines when you aren't expecting it; which shows up as "extra spacing" you weren't looking for. If so, there isn't anything you can do about that, other than fix the size of your text box to the space available on the paper.

But TBH, just filling a TextBox with text and printing it probably isn't the best way to do a receipt - you should consider doing "proper formatting" of the actual print - it's very rare to see a receipt that just has same sized text throughout, without any bold, logo, small address detail, or even a "tracking" barcode - none of which can be included in a standard TextBox.


我在使用默认打印时遇到了同样的问题字体(Microsoft Sans Serif)。如果你可以使用像Arial这样的TTF字体这个问题可能不存在。



你可以尝试一些像



I have seen the same issue while printing using the default font (Microsoft Sans Serif). If you can use TTF fonts like Arial this issue may not be there.

You can try some thing like

Private textToPrint As String
Private printFont As Font

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    textToPrint = TextBox1.Text
    printFont = New Font("Arial", 10)

    PrintPreviewDialog1.ShowDialog()
End Sub

Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    Dim charsOnPage As Integer = 0
    Dim linesPerPage As Integer = 0

    e.Graphics.MeasureString(textToPrint, printFont, e.MarginBounds.Size, StringFormat.GenericTypographic, charsOnPage, linesPerPage)

    e.Graphics.DrawString(textToPrint, printFont, Brushes.Black, e.MarginBounds, StringFormat.GenericTypographic)

    textToPrint = textToPrint.Substring(charsOnPage)

    e.HasMorePages = (textToPrint.Length > 0)
End Sub


这篇关于如何在VB.NET中减少打印收据中单词之间的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆