-
Mar 9th, 2023, 11:09 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Why Bruhses.White are not printing anything.
Hello!
I´m printing simple barcodes in my ticket printer, I want to add some extra lines at the end of each barcode, so I print a " " (black space) in a loop, but the extra lines are not added.
I noticed that if I print any other printable character, it works and it prints the character as many times as specified.
Also if I print any printable character using Brushes.White the character is not printed.
I've tried with:
VB.NET Code:
For j = 1 To CInt(NumericUpDown2.Text)
yPos += 16
e.Graphics.DrawString(" ", MyFont, Brushes.Black, 0, yPos)
Next
and:
VB.NET Code:
For j = 1 To CInt(NumericUpDown2.Text)
yPos += 16
Dim MyBrush As New SolidBrush(Color.White)
Dim Rect_x As New RectangleF(0, yPos, 10, yPos + 16)
e.Graphics.FillRectangle(MyBrush, Rect_x)
Next
none of the above is working.
Is there an invisible character I can print? so I can add some line feeds at the end of each barcode.
Am I missing something?
Last edited by Spybot; Mar 9th, 2023 at 11:21 PM.
-
Mar 9th, 2023, 11:32 PM
#2
Re: Why Bruhses.White are not printing anything.
I don't know for sure but I would expect that, when printing, white is assumed to be the background colour so printing white would mean not printing anything, i.e. not laying down any ink/toner, and letting the background colour show through. It sounds like that's what you're seeing, so that would mean that everything is working as it should. In that case, if you print nothing but white then you effectively print nothing.
What would be the point of using FillRectangle anyway? When you call DrawString, you specify exactly where you want the text drawn. That won't change due to any calls to any other Draw or Fill methods. It's not clear to me exactly what you're trying to achieve.
-
Mar 10th, 2023, 01:46 AM
#3
Thread Starter
Hyperactive Member
Re: Why Bruhses.White are not printing anything.
Hi Jmc.
"It's not clear to me exactly what you're trying to achieve." I'm just trying to add some extra lines after the bar code is printed, so I thought printing a space or a white rectangle would give me that effect, now I see using a white brush is useless.
What I'm trying to do is something like this, all I'm missing are the empty lines between each barcode. btw the number of empty lines is given by a numericupdown control.
Attachment 187137
-
Mar 10th, 2023, 02:09 AM
#4
Re: Why Bruhses.White are not printing anything.
You don't need empty lines. When you call DrawString or DrawRectangle or whatever, you get to specify EXACTLY where it should be drawn. If you want space between each barcode, simply increase the Y component of the Point or Rectangle you provide when you call those methods each time. I would be writing a method that draws a single barcode and takes the vertical position as an argument. Then calling that method in a loop with an increasing Y value. If you do something like this:
vb.net Code:
For i = 0 to barcodes.GetUpperBound(0)
Dim y = 100 * i
'...
Next
That will give you a y value that is zero for the first barcode, 100 for the second, 200 for the third and so on. You simply adjust the multiplier to whatever distance you want between the tops of adjacent barcode blocks.
-
Mar 10th, 2023, 11:59 AM
#5
Thread Starter
Hyperactive Member
Re: Why Bruhses.White are not printing anything.
My problem is not the loop, my problem is the object I have to provide, if it's a rectangle or a text symbol, it has to be drawn with a Brush, if I specify Brushes.Black it'll printed (That, I don't want.) If I chose Brushes.White, it would not print anything, and I will not get the empty lines that I need.
So, if I draw something it has to be white or transparent in order to produce an empty line (I guess).
How do I do that?
-
Mar 10th, 2023, 02:55 PM
#6
Re: Why Bruhses.White are not printing anything.
If Brushes.White is not working, go for Brushes.AlmostWhite. Okay, I realize that's not a real thing, but you can make your own brush with your own color based on RGB values. White would be (255,255,255), so try (254,255,255). You couldn't tell the difference, but Windows can.
My usual boring signature: Nothing
-
Mar 10th, 2023, 09:34 PM
#7
Re: Why Bruhses.White are not printing anything.
The point is that you don't need "empty lines". Think about it. If you were standing at a wall and you wanted to paint something at the top and something at the bottom, would you have to paint something in the middle in order to create the space between them? Of course you wouldn't. The same applies here. Just print whatever you want to print wherever you want to print it. If you print something well below something else then there will be a gap between them. I'm not seeing where the problem is here.
-
Mar 10th, 2023, 10:53 PM
#8
Re: Why Bruhses.White are not printing anything.
I just ran this code:
vb.net Code:
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim lines = {"Hello", "World", "Goodbye"}
For i = 0 To lines.GetUpperBound(0)
Dim verticalOffset = 100 * i
e.Graphics.DrawString(lines(i), Font, Brushes.Black, 20, 20 + verticalOffset)
Next
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PrintPreviewDialog1.ShowDialog()
End Sub
and the output is shown in the image below:
As you can see, I was able to create space between each pair of printed lines without any dummy printing or "blank lines". Am I missing something? Can you explain why this same principle cannot be used to achieve what you want?
-
Mar 14th, 2023, 03:37 AM
#9
Thread Starter
Hyperactive Member
Re: Why Bruhses.White are not printing anything.
Replacing those texts with barcodes, I end up with...
VB.NET Code:
For i = 1 To CInt(NumericUpDown_Copies.Text)
'draw product name...
'generate & draw barcode...
'draw numeric code...
If NumericUpDown_VeticalOffset.Text <> "" Then
If CInt(NumericUpDown_VeticalOffset.Text) > 0 Then
For j = 1 To CInt(NumericUpDown_VeticalOffset.Text)
yPos += 6 * j
Next
End If
End If
-
Mar 14th, 2023, 07:08 AM
#10
Re: [RESOLVED] Why Bruhses.White are not printing anything.
Can we assume that that is what you wanted?
-
Mar 15th, 2023, 02:17 PM
#11
Re: [RESOLVED] Why Bruhses.White are not printing anything.
Since that printer is a continuous paper roll rather than a sheet, I don't know that addressing with a Y position is applicable.
It is likely relative "line" oriented, so you would just use carriage control characters to control the movement of the paper.
I would think that printing out a few Environment.NewLine characters may provide extra line spacing in your output.
In fact I would think you could append a few NewLine characters in a single string and just print that string to skip a few lines, rather than use a loop.
But I haven't worked with a paper roll type printer.
Last edited by passel; Mar 15th, 2023 at 02:21 PM.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|