?
Solved

VB.Net - Print components in a Form

Posted on 2013-06-24
12
Medium Priority
?
299 Views
Last Modified: 2014-01-24
Hi,
I have to print blank pages with some compay info.
The form information prints ok but it is also printing the form background (greyed).
Can someone help to maky this form only prints the desired information without the Form 'greyed' background?

This is the code I am using:

Private Sub btnPrintDatos_Click(sender As Object, e As EventArgs) Handles btnPrintDatos.Click

        If btnImpresora.Text = "Favor seleccione Impresora..." Then
            MsgBox("Favor seleccione una impresora")
        Else

            Dim folio_inicio, folio_final As Integer
            Dim impresora As String
            impresora = btnImpresora.Text
            folio_inicio = txtFolioInicio.Text
            folio_final = txtFolioFinal.Text

            For x = folio_inicio To folio_final

                txtFolioActual.Text = x
                'hacemos invisibles los controles que no deseamos que aparezcan
                btnPrintDatos.Visible = False
                lblFolioInicio.Visible = False
                lblFolioFinal.Visible = False
                txtFolioInicio.Visible = False
                txtFolioFinal.Visible = False
                lblImpresora.Visible = False
                btnImpresora.Visible = False

'I tried using the follow piece of code to hide the form background but it failed :(
                Me.TransparencyKey = Me.BackColor
                Me.AllowTransparency = True
                Me.BackColor = Me.TransparencyKey

                lblFolioActual.Focus()

                'actualizamos el formulario, para actualizar el folio actual
                PrintForm1.Form.Update()

                'configuramos la impresora
                Me.PrintForm1.PrinterSettings.PrinterName = impresora

                'define Margins
                PrintForm1.PrinterSettings.DefaultPageSettings.Margins = New System.Drawing.Printing.Margins(0, 0, 0, 0)

'we now print!
PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.CompatibleModeClientAreaOnly)


                'hacemos visible los controles nuevamente
                Me.Visible = True
                btnPrintDatos.Visible = True
                lblFolioInicio.Visible = True
                lblFolioFinal.Visible = True
                txtFolioInicio.Visible = True
                txtFolioFinal.Visible = True
                lblImpresora.Visible = True
                btnImpresora.Visible = True

            Next x
            MsgBox("Impresion terminada hermano, que tengas un gran día :)")
        End If

    End Sub

    Private Sub btnImpresora_Click(sender As Object, e As EventArgs) Handles btnImpresora.Click
        Dim impresora As String = PrintDialog1.ShowDialog()
        Dim impresora_nombre As String = PrintDialog1.PrinterSettings.PrinterName
        btnImpresora.Text = impresora_nombre
    End Sub

Open in new window

0
Comment
Question by:José Perez
  • 6
  • 6
12 Comments
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 39274029
change the background of the form to white just before the print, and restore its background afterwards.
0
 
LVL 2

Author Comment

by:José Perez
ID: 39311844
It didn't work. The background have not changed anything. I did it but it is still printing in gray :(
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 39313222
let me try i'll get back to you
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 39313424
use this code:
Private Sub btnPrintDatos_Click(sender As Object, e As EventArgs) Handles btnPrintDatos.Click

        If btnImpresora.Text = "Favor seleccione Impresora..." Then
            MsgBox("Favor seleccione una impresora")
        Else

            Dim folio_inicio, folio_final As Integer
            Dim impresora As String
            impresora = btnImpresora.Text
            folio_inicio = txtFolioInicio.Text
            folio_final = txtFolioFinal.Text

            For x = folio_inicio To folio_final

                txtFolioActual.Text = x
                'hacemos invisibles los controles que no deseamos que aparezcan
                btnPrintDatos.Visible = False
                lblFolioInicio.Visible = False
                lblFolioFinal.Visible = False
                txtFolioInicio.Visible = False
                txtFolioFinal.Visible = False
                lblImpresora.Visible = False
                btnImpresora.Visible = False

'I tried using the follow piece of code to hide the form background but it failed :(
                Me.TransparencyKey = Me.BackColor
                Me.AllowTransparency = True
                Me.BackColor = Me.TransparencyKey

                lblFolioActual.Focus()

                'actualizamos el formulario, para actualizar el folio actual
                PrintForm1.Form.Update()

                'configuramos la impresora
                Me.PrintForm1.PrinterSettings.PrinterName = impresora

                'define Margins
                PrintForm1.PrinterSettings.DefaultPageSettings.Margins = New System.Drawing.Printing.Margins(0, 0, 0, 0)

dim defaultColor As Color = Me.Background
Me.BackColor = Color.White
Me.Update()
'we now print!
PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.ClientAreaOnly)
Me.BackColor = defaultColor 
Me.Update()

                'hacemos visible los controles nuevamente
                Me.Visible = True
                btnPrintDatos.Visible = True
                lblFolioInicio.Visible = True
                lblFolioFinal.Visible = True
                txtFolioInicio.Visible = True
                txtFolioFinal.Visible = True
                lblImpresora.Visible = True
                btnImpresora.Visible = True

            Next x
            MsgBox("Impresion terminada hermano, que tengas un gran día :)")
        End If

    End Sub

    Private Sub btnImpresora_Click(sender As Object, e As EventArgs) Handles btnImpresora.Click
        Dim impresora As String = PrintDialog1.ShowDialog()
        Dim impresora_nombre As String = PrintDialog1.PrinterSettings.PrinterName
        btnImpresora.Text = impresora_nombre
    End Sub

Open in new window

0
 
LVL 2

Author Comment

by:José Perez
ID: 39314185
It displays an error on "Me.Background". It says "Not a memeber of Form1"

'define Margins
                PrintForm1.PrinterSettings.DefaultPageSettings.Margins = New System.Drawing.Printing.Margins(0, 0, 0, 0)

                Dim defaultColor As Color = Me.Background 'here is the error displayed

Open in new window

0
 
LVL 42

Accepted Solution

by:
Meir Rivkin earned 500 total points
ID: 39314247
change Background to Backcolor
0
 
LVL 2

Author Comment

by:José Perez
ID: 39314537
mmm it fixed the background issue but the text is been printed 'blurry'
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 39314611
i actually try this code with our office printer and it looks fine.
do the font looks different when u print in grey rather than in white background?
0
 
LVL 2

Author Comment

by:José Perez
ID: 39314683
no, it sees the same but when the form was printing in gray I didn't notice.

If I attached a zip file for you to try in your printer would please check?
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 39316736
sure
0
 
LVL 2

Author Comment

by:José Perez
ID: 39317254
It did not allow me to upload the file due to site restrictions so I uplodad a pdf rendition of the final printing. There you can also see that it is 'blurry'.
1.pdf
0
 
LVL 2

Author Closing Comment

by:José Perez
ID: 39806512
Finally the text was blurry but it works.
Thanks a lot!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Integration Management Part 2
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question