Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.Net - Print components in a Form

Posted on 2013-06-24
12
Medium Priority
?
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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)…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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