none
Visual basic 2015 and Printing a document from details captured from textboxes combobox and labels(Displayed via database application)

    Question

  • Hi

    I want to Printing a document from details captured from textboxes combo box and labels(Displayed via database application) in Visual basic 2015.

    Saturday, March 18, 2017 2:11 PM

Answers

  • Hi sheelnath,

    Based on your description, I suggest you to load data into datagridview and then print these data. The code about print below you can refer to.

    Print code:

    Private bitmap As Bitmap
    Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
        'Add a Panel control.
        Dim panel As New Panel()
        Me.Controls.Add(panel)
     
        'Create a Bitmap of size same as that of the Form.
        Dim grp As Graphics = panel.CreateGraphics()
        Dim formSize As Size = Me.ClientSize
        bitmap = New Bitmap(formSize.Width, formSize.Height, grp)
        grp = Graphics.FromImage(bitmap)
     
        'Copy screen area that that the Panel covers.
        Dim panelLocation As Point = PointToScreen(panel.Location)
        grp.CopyFromScreen(panelLocation.X, panelLocation.Y, 0, 0, formSize)
     
        'Show the Print Preview Dialog.
        printPreviewDialog1.Document = printDocument1
        printPreviewDialog1.PrintPreviewControl.Zoom = 1
        printPreviewDialog1.ShowDialog()
    End Sub
     
    Private Sub PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles printDocument1.PrintPage
        'Print the contents.
        e.Graphics.DrawImage(bitmap, 0, 0)
    End Sub
    

    Hope it is helpful to you.

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by sheelnath Monday, January 29, 2018 4:38 PM
    Monday, March 20, 2017 8:10 AM
    Moderator

All replies

  • OK, so use a PrintDocument and draw the data according to the layout you desire.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Saturday, March 18, 2017 2:15 PM
    Moderator
  • Hi sheelnath,

    Based on your description, I suggest you to load data into datagridview and then print these data. The code about print below you can refer to.

    Print code:

    Private bitmap As Bitmap
    Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
        'Add a Panel control.
        Dim panel As New Panel()
        Me.Controls.Add(panel)
     
        'Create a Bitmap of size same as that of the Form.
        Dim grp As Graphics = panel.CreateGraphics()
        Dim formSize As Size = Me.ClientSize
        bitmap = New Bitmap(formSize.Width, formSize.Height, grp)
        grp = Graphics.FromImage(bitmap)
     
        'Copy screen area that that the Panel covers.
        Dim panelLocation As Point = PointToScreen(panel.Location)
        grp.CopyFromScreen(panelLocation.X, panelLocation.Y, 0, 0, formSize)
     
        'Show the Print Preview Dialog.
        printPreviewDialog1.Document = printDocument1
        printPreviewDialog1.PrintPreviewControl.Zoom = 1
        printPreviewDialog1.ShowDialog()
    End Sub
     
    Private Sub PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles printDocument1.PrintPage
        'Print the contents.
        e.Graphics.DrawImage(bitmap, 0, 0)
    End Sub
    

    Hope it is helpful to you.

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by sheelnath Monday, January 29, 2018 4:38 PM
    Monday, March 20, 2017 8:10 AM
    Moderator