Usuário com melhor resposta
Imprimir form sem margens/barra de rolagem

Pergunta
-
Olá amigos,
Gostaria de imprimir uma form, sem margens.
Já tentei várias coisas, mas só consigo o que se vê na imagem.
Para além disso gostaria de colocar uma barra de rolagem no form para trabalhar no formato de uma folha A4.
Posso contar com a vossa ajuda?
Cumprimentos.- Movido AndreAlvesLimaModerator quinta-feira, 19 de abril de 2012 10:56 (De:Visual Studio - Geral)
Respostas
-
Imports System.Drawing.Printing Public Class Form1 Private WithEvents pd As New PrintDocument Private WithEvents Button1 As New Button With {.Location = New Point(50, 50), .Text = "print", .Parent = Me} Private bmp As Bitmap Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click bmp = New Bitmap(Panel1.ClientSize.Width, Panel1.ClientSize.Height) Panel1.DrawToBitmap(bmp, Panel1.ClientRectangle) pd.Print() End Sub Private Sub pd_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pd.PrintPage Dim area = e.PageSettings.PrintableArea Dim ar1 = area.Width / area.Height Dim ar2 = CSng(bmp.Width / bmp.Height) If ar1 > ar2 Then Dim NewWidth = bmp.Width * area.Height / bmp.Height Dim x = (area.Width - NewWidth) / 2 e.Graphics.DrawImage(bmp, x, area.Top, NewWidth, area.Height) Else Dim NewHeight = bmp.Height * area.Width / bmp.Width Dim y = (area.Height - NewHeight) / 2 e.Graphics.DrawImage(bmp, area.Left, y, area.Width, NewHeight) End If e.HasMorePages = False End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Using g = Graphics.FromHwnd(IntPtr.Zero) Panel1.Size = New Size(CInt(21 / 2.54 * g.DpiX), CInt(29.7 / 2.54 * g.DpiY)) End Using End Sub End Class
- Marcado como Resposta Vitor Patrício sábado, 21 de abril de 2012 00:23
Todas as Respostas
-
-
Imports System.Drawing.Printing
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
Dim ps As New PageSettings
Dim area = ps.PrintableArea
Dim ar = area.Width / area.Height
Using g = Graphics.FromHwnd(IntPtr.Zero)
Size = New Size(CInt(21 / 2.54 * g.DpiX), CInt(29.7 / 2.54 * g.DpiY))
End Using
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
' If you don't want the print button to print the print button
Button1.Visible = True
' Set the PrintAction to display a Print Preview dialog
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
' This prints a copy of the form as it appears in the PrintPreview
PrintForm1.Print()
' Display the print button again on the form
Button1.Visible = True
End Sub
End Class -
Prezado(a),
Estou migrando seu post para o fórum de Windows Forms.
Por favor, das próximas vezes que tiver alguma dúvida relacionada a esse assunto, poste por lá.
Obrigado.André Alves de Lima
Microsoft MVP - Client App Dev
Visite o meu site: http://www.andrealveslima.com.br
Me siga no Twitter: @andrealveslima -
Imports System.Drawing.Printing Public Class Form1 Private WithEvents pd As New PrintDocument Private WithEvents Button1 As New Button With {.Location = New Point(50, 50), .Text = "print", .Parent = Me} Private bmp As Bitmap Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click bmp = New Bitmap(Panel1.ClientSize.Width, Panel1.ClientSize.Height) Panel1.DrawToBitmap(bmp, Panel1.ClientRectangle) pd.Print() End Sub Private Sub pd_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pd.PrintPage Dim area = e.PageSettings.PrintableArea Dim ar1 = area.Width / area.Height Dim ar2 = CSng(bmp.Width / bmp.Height) If ar1 > ar2 Then Dim NewWidth = bmp.Width * area.Height / bmp.Height Dim x = (area.Width - NewWidth) / 2 e.Graphics.DrawImage(bmp, x, area.Top, NewWidth, area.Height) Else Dim NewHeight = bmp.Height * area.Width / bmp.Width Dim y = (area.Height - NewHeight) / 2 e.Graphics.DrawImage(bmp, area.Left, y, area.Width, NewHeight) End If e.HasMorePages = False End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Using g = Graphics.FromHwnd(IntPtr.Zero) Panel1.Size = New Size(CInt(21 / 2.54 * g.DpiX), CInt(29.7 / 2.54 * g.DpiY)) End Using End Sub End Class
- Marcado como Resposta Vitor Patrício sábado, 21 de abril de 2012 00:23
-