Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Print at the center

Print at the center

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    terence2004
    wrote on last edited by
    #1

    Can someone tell me how to print the text at the center of the paper? i am using a receipt print with a maximum of 40 characters per line Proper Planning is way to success

    D 1 Reply Last reply
    0
    • T terence2004

      Can someone tell me how to print the text at the center of the paper? i am using a receipt print with a maximum of 40 characters per line Proper Planning is way to success

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Since you know the width of the printer you pad the beginning of the string with spaces. Take the length of the line you want to print away from the width of the printer, then divide that difference by 2 to get the number of spaces to add on both sides of the test you want to print, but only add it to the beginning of the text:

      Dim sText As String = "Text to print Centered"
      Dim iPad As Integer
      

      iPad = ( 40 - sText.Length ) / 2
      sText = New String( Chr(32), iPad ) & sText

      RageInTheMachine9532

      T 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Since you know the width of the printer you pad the beginning of the string with spaces. Take the length of the line you want to print away from the width of the printer, then divide that difference by 2 to get the number of spaces to add on both sides of the test you want to print, but only add it to the beginning of the text:

        Dim sText As String = "Text to print Centered"
        Dim iPad As Integer
        

        iPad = ( 40 - sText.Length ) / 2
        sText = New String( Chr(32), iPad ) & sText

        RageInTheMachine9532

        T Offline
        T Offline
        terence2004
        wrote on last edited by
        #3

        New string is an unexperted identified. so how?? Proper Planning is way to success

        D 1 Reply Last reply
        0
        • T terence2004

          New string is an unexperted identified. so how?? Proper Planning is way to success

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Are you using VB6 or VB.NET? The code sample works as advertised on VB.NET. The equivelent code in VB6 would be this:

          Dim sText As String
          Dim iPad As Long
          

          sText = "Text to print Centered"
          iPad = ( 40 - Len(sText) ) / 2
          sText = String$( iPad, 32 ) & sText

          RageInTheMachine9532

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups