Solved

VB.Net - Print components in a Form

Posted on 2013-06-24
12
289 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:sedgwick
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:sedgwick
ID: 39313222
let me try i'll get back to you
0
 
LVL 42

Expert Comment

by:sedgwick
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:
sedgwick earned 250 total points
ID: 39314247
change Background to Backcolor
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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:sedgwick
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:sedgwick
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now