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. Printing with vb.net (Urgent)

Printing with vb.net (Urgent)

Scheduled Pinned Locked Moved Visual Basic
csharphelptutorial
6 Posts 3 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.
  • H Offline
    H Offline
    HemaRawat
    wrote on last edited by
    #1

    I have to create a Entry Ticket & then Print it Now How to Print the VB.net forms with all controls on it 1 Logo (PictureBox) 2. Labels of Name & Address Etc 3. Barcode is also on my entry ticket form Except the Print Button on it. Waiting for all early replies Thanks in advance for this esteemed help Hema Chaudhry

    U B 2 Replies Last reply
    0
    • H HemaRawat

      I have to create a Entry Ticket & then Print it Now How to Print the VB.net forms with all controls on it 1 Logo (PictureBox) 2. Labels of Name & Address Etc 3. Barcode is also on my entry ticket form Except the Print Button on it. Waiting for all early replies Thanks in advance for this esteemed help Hema Chaudhry

      U Offline
      U Offline
      uktrips007
      wrote on last edited by
      #2

      Easy! first of all make print button property visible=false.then press F5 to run it. when form get loaded press prt screen(print screen) button of ur keyboard.then paste it in paint application.now from selection tool select the form and copy it.after copying successfully open ms word document and paste it.then take out print after adjusting form image on page best of luck Hema. bye!! Uttam if I helped u any way, mail me at trickyuk001@rediffmail.com try to be the best... whereever you go, -- modified at 2:54 Monday 12th December, 2005

      H 1 Reply Last reply
      0
      • U uktrips007

        Easy! first of all make print button property visible=false.then press F5 to run it. when form get loaded press prt screen(print screen) button of ur keyboard.then paste it in paint application.now from selection tool select the form and copy it.after copying successfully open ms word document and paste it.then take out print after adjusting form image on page best of luck Hema. bye!! Uttam if I helped u any way, mail me at trickyuk001@rediffmail.com try to be the best... whereever you go, -- modified at 2:54 Monday 12th December, 2005

        H Offline
        H Offline
        HemaRawat
        wrote on last edited by
        #3

        Thanks for your Prompt Reply, But Dear , I want to print the the form from the VB.net Code itself Not from the Paint . Means My application has the option print preview & print etc . Then CLick on Print will print the desired form. AnyWay Thanks Plz reply If you know about that. Thansk in advance Hema Chaudhry

        U 1 Reply Last reply
        0
        • H HemaRawat

          Thanks for your Prompt Reply, But Dear , I want to print the the form from the VB.net Code itself Not from the Paint . Means My application has the option print preview & print etc . Then CLick on Print will print the desired form. AnyWay Thanks Plz reply If you know about that. Thansk in advance Hema Chaudhry

          U Offline
          U Offline
          uktrips007
          wrote on last edited by
          #4

          ok Madam, I m here 2 help u out.I have an idea.first u save ur form as a picture.then using code u can print out ur picture which will be ur form.try this code to print out.use print.picture method to take print out picture. dim sngLeft as single dim sngTop as single sngLeft = (prn.scalewidth - prn.scalex(pic.width,vbhimetric, prn.scalemode)) / 2 sngTop = (prn.scaleheight - prn.scaley(pic.height, vbhimetric, prn.scalemode)) / 2 prn.Paintpicture pic, sngLeft, sngTop if u don't get result Try this link follows. http://www.vb-helper.com/howto_net_print_form_image.html Hope so u'll get ur result.if this help you mail me at trickyuk001@rediffmail.com.& try to help me in solving my problem. Thanking you Uttam Kumar mumbai,convonix.inc try to be the best... whereever you go, -- modified at 5:24 Monday 12th December, 2005

          1 Reply Last reply
          0
          • H HemaRawat

            I have to create a Entry Ticket & then Print it Now How to Print the VB.net forms with all controls on it 1 Logo (PictureBox) 2. Labels of Name & Address Etc 3. Barcode is also on my entry ticket form Except the Print Button on it. Waiting for all early replies Thanks in advance for this esteemed help Hema Chaudhry

            B Offline
            B Offline
            Briga
            wrote on last edited by
            #5

            The formally correct solution is probably the best one although is a bit more complex. But not too much. You have better to use a PrintDocument class. There's plenty of documentation and samples on MSDN and here as well. To summarize: 1) Create a desgin time a printdocument in the form (i.e. called pDoc) 2) Double click on it to open the editor in the printing function 3) Write the code to print your data (***) 4) From the button invoke the pDoc.Print method. (***) I'm not able to write the full code you need but it should be something with: e.graphics.drawstring for each text you want to print e.graphics.drawimage for each image you want to print. Here's an example from the documentation

            Public Class PrintingExample
            Inherits System.Windows.Forms.Form
            Private components As System.ComponentModel.Container
            Private printButton As System.Windows.Forms.Button
            Private printFont As Font
            Private streamToPrint As StreamReader

            Public Sub New()
                ' The Windows Forms Designer requires the following call.
                InitializeComponent()
            End Sub    
            
            ' The Click event is raised when the user clicks the Print button.
            Private Sub printButton\_Click(sender As Object, e As EventArgs)
                Try
                    streamToPrint = New StreamReader("C:\\My Documents\\MyFile.txt")
                    Try
                        printFont = New Font("Arial", 10)
                        Dim pd As New PrintDocument()
                        AddHandler pd.PrintPage, AddressOf Me.pd\_PrintPage
                        pd.Print()
                    Finally
                        streamToPrint.Close()
                    End Try
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End Sub    
            
            ' The PrintPage event is raised for each page to be printed.
            Private Sub pd\_PrintPage(sender As Object, ev As PrintPageEventArgs)
                Dim linesPerPage As Single = 0
                Dim yPos As Single = 0
                Dim count As Integer = 0
                Dim leftMargin As Single = ev.MarginBounds.Left
                Dim topMargin As Single = ev.MarginBounds.Top
                Dim line As String = Nothing
                
                ' Calculate the number of lines per page.
                linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)
                
                ' Print each line of the file.
                While count < linesPerPage
                    line = streamToPrint.ReadLine()
                    If line Is Nothing Then
                        Exit While
            
            H 1 Reply Last reply
            0
            • B Briga

              The formally correct solution is probably the best one although is a bit more complex. But not too much. You have better to use a PrintDocument class. There's plenty of documentation and samples on MSDN and here as well. To summarize: 1) Create a desgin time a printdocument in the form (i.e. called pDoc) 2) Double click on it to open the editor in the printing function 3) Write the code to print your data (***) 4) From the button invoke the pDoc.Print method. (***) I'm not able to write the full code you need but it should be something with: e.graphics.drawstring for each text you want to print e.graphics.drawimage for each image you want to print. Here's an example from the documentation

              Public Class PrintingExample
              Inherits System.Windows.Forms.Form
              Private components As System.ComponentModel.Container
              Private printButton As System.Windows.Forms.Button
              Private printFont As Font
              Private streamToPrint As StreamReader

              Public Sub New()
                  ' The Windows Forms Designer requires the following call.
                  InitializeComponent()
              End Sub    
              
              ' The Click event is raised when the user clicks the Print button.
              Private Sub printButton\_Click(sender As Object, e As EventArgs)
                  Try
                      streamToPrint = New StreamReader("C:\\My Documents\\MyFile.txt")
                      Try
                          printFont = New Font("Arial", 10)
                          Dim pd As New PrintDocument()
                          AddHandler pd.PrintPage, AddressOf Me.pd\_PrintPage
                          pd.Print()
                      Finally
                          streamToPrint.Close()
                      End Try
                  Catch ex As Exception
                      MessageBox.Show(ex.Message)
                  End Try
              End Sub    
              
              ' The PrintPage event is raised for each page to be printed.
              Private Sub pd\_PrintPage(sender As Object, ev As PrintPageEventArgs)
                  Dim linesPerPage As Single = 0
                  Dim yPos As Single = 0
                  Dim count As Integer = 0
                  Dim leftMargin As Single = ev.MarginBounds.Left
                  Dim topMargin As Single = ev.MarginBounds.Top
                  Dim line As String = Nothing
                  
                  ' Calculate the number of lines per page.
                  linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)
                  
                  ' Print each line of the file.
                  While count < linesPerPage
                      line = streamToPrint.ReadLine()
                      If line Is Nothing Then
                          Exit While
              
              H Offline
              H Offline
              HemaRawat
              wrote on last edited by
              #6

              Thank you very much I will apply your approach & then get back to u Thanks again for this help Hema Chaudhry

              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