Results 1 to 11 of 11

Thread: [RESOLVED] Why Bruhses.White are not printing anything.

  1. #1

    Thread Starter
    Hyperactive Member Spybot's Avatar
    Join Date
    Jan 2019
    Posts
    329

    Resolved [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:
    1. For j = 1 To CInt(NumericUpDown2.Text)
    2.   yPos += 16
    3.   e.Graphics.DrawString(" ", MyFont, Brushes.Black, 0, yPos)
    4. Next

    and:
    VB.NET Code:
    1. For j = 1 To CInt(NumericUpDown2.Text)
    2.   yPos += 16
    3.   Dim MyBrush As New SolidBrush(Color.White)
    4.   Dim Rect_x As New RectangleF(0, yPos, 10, yPos + 16)
    5.   e.Graphics.FillRectangle(MyBrush, Rect_x)
    6. 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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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.

  3. #3

    Thread Starter
    Hyperactive Member Spybot's Avatar
    Join Date
    Jan 2019
    Posts
    329

    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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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:
    1. For i = 0 to barcodes.GetUpperBound(0)
    2.     Dim y = 100 * i
    3.  
    4.     '...
    5. 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.

  5. #5

    Thread Starter
    Hyperactive Member Spybot's Avatar
    Join Date
    Jan 2019
    Posts
    329

    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?

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    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

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Why Bruhses.White are not printing anything.

    I just ran this code:
    vb.net Code:
    1. Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    2.     Dim lines = {"Hello", "World", "Goodbye"}
    3.  
    4.     For i = 0 To lines.GetUpperBound(0)
    5.         Dim verticalOffset = 100 * i
    6.  
    7.         e.Graphics.DrawString(lines(i), Font, Brushes.Black, 20, 20 + verticalOffset)
    8.     Next
    9. End Sub
    10.  
    11. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    12.     PrintPreviewDialog1.ShowDialog()
    13. End Sub
    and the output is shown in the image below:

    Name:  PrintingWithVerticalOffset.png
Views: 138
Size:  2.4 KB

    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?

  9. #9

    Thread Starter
    Hyperactive Member Spybot's Avatar
    Join Date
    Jan 2019
    Posts
    329

    Re: Why Bruhses.White are not printing anything.

    Replacing those texts with barcodes, I end up with...
    VB.NET Code:
    1. For i = 1 To CInt(NumericUpDown_Copies.Text)
    2. 'draw product name...
    3. 'generate & draw barcode...
    4. 'draw numeric code...
    5.  
    6.  If NumericUpDown_VeticalOffset.Text <> "" Then
    7.       If CInt(NumericUpDown_VeticalOffset.Text) > 0 Then
    8.            For j = 1 To CInt(NumericUpDown_VeticalOffset.Text)
    9.                 yPos += 6 * j
    10.            Next
    11.      End If
    12.  End If

    Name:  1678782887901.jpg
Views: 166
Size:  52.7 KB

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [RESOLVED] Why Bruhses.White are not printing anything.

    Can we assume that that is what you wanted?

  11. #11
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    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
  •  



Click Here to Expand Forum to Full Width