Meilleur auteur de réponses
Imprimer un panel

Question
-
Bonsoir a tous
J’ai une question sue l’aperçu avant l’impression
Je place des objets dans un panel1 et j'envoie le panel dans le PrintDocument1_PrintPage
Quand je demande l’aperçu mont panel se trouve aux milieux de l’aperçu
Je voudrais le placer en haut de l'aperçu pour l'imprimer sans le début vide
Voici le code il doit avoir une erreur
Je vous place le code que j'ai trouver
Et merci d’avance
Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.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
- Modifié Orleandeux jeudi 4 juin 2020 07:06
Réponses
-
Avec DrawImage, on le place où l'on veut
Par exemple, test en haut à gauche (10, 10) =>
(rajouter un bouton pour le Button1_Click...)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load CreateMyPanel() CenterToScreen() End Sub Friend WithEvents panel1 As Panel ' MSDN code Public Sub CreateMyPanel() panel1 = New System.Windows.Forms.Panel() Dim textBox1 As New TextBox() Dim label1 As New Label() ' Initialize the Panel control. panel1.Location = New Point(56, 72) panel1.Size = New Size(264, 152) ' Set the Borderstyle for the Panel to three-dimensional. panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D ' Initialize the Label and TextBox controls. label1.Location = New Point(16, 16) label1.Text = "label1" label1.Size = New Size(104, 16) textBox1.Location = New Point(16, 32) textBox1.Text = "TextBox" textBox1.Size = New Size(152, 20) ' Add the Panel control to the form. Me.Controls.Add(panel1) ' Add the Label and TextBox controls to the Panel. panel1.Controls.Add(label1) panel1.Controls.Add(textBox1) End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim printdoc1 As PrintDocument = New PrintDocument AddHandler printdoc1.PrintPage, AddressOf Me.printdoc1_PrintPage Dim previewdlg As PrintPreviewDialog = New PrintPreviewDialog previewdlg.Document = printdoc1 previewdlg.ShowDialog() End Sub Private Sub printdoc1_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Using bmp As New Bitmap(Me.Width, Me.Height) Me.panel1.DrawToBitmap(bmp, New Rectangle(0, 0, panel1.Width, panel1.Height)) Dim pageaBounds As Rectangle = e.PageBounds e.Graphics.DrawImage(bmp, 10, 10) End Using End Sub
- Marqué comme réponse Orleandeux jeudi 4 juin 2020 20:31
-
je ne voie pas le sub CenterToScreen()
C'est juste une API standard pour centrer la Form Form.CenterToScreen
- Marqué comme réponse Orleandeux jeudi 4 juin 2020 20:30
-
Bonsoir
Merci Castorix31
excuse moi ou je n’ai pas compris
je ne voie pas le sub CenterToScreen()
- Marqué comme réponse Orleandeux jeudi 4 juin 2020 20:30
Toutes les réponses
-
Avec DrawImage, on le place où l'on veut
Par exemple, test en haut à gauche (10, 10) =>
(rajouter un bouton pour le Button1_Click...)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load CreateMyPanel() CenterToScreen() End Sub Friend WithEvents panel1 As Panel ' MSDN code Public Sub CreateMyPanel() panel1 = New System.Windows.Forms.Panel() Dim textBox1 As New TextBox() Dim label1 As New Label() ' Initialize the Panel control. panel1.Location = New Point(56, 72) panel1.Size = New Size(264, 152) ' Set the Borderstyle for the Panel to three-dimensional. panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D ' Initialize the Label and TextBox controls. label1.Location = New Point(16, 16) label1.Text = "label1" label1.Size = New Size(104, 16) textBox1.Location = New Point(16, 32) textBox1.Text = "TextBox" textBox1.Size = New Size(152, 20) ' Add the Panel control to the form. Me.Controls.Add(panel1) ' Add the Label and TextBox controls to the Panel. panel1.Controls.Add(label1) panel1.Controls.Add(textBox1) End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim printdoc1 As PrintDocument = New PrintDocument AddHandler printdoc1.PrintPage, AddressOf Me.printdoc1_PrintPage Dim previewdlg As PrintPreviewDialog = New PrintPreviewDialog previewdlg.Document = printdoc1 previewdlg.ShowDialog() End Sub Private Sub printdoc1_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Using bmp As New Bitmap(Me.Width, Me.Height) Me.panel1.DrawToBitmap(bmp, New Rectangle(0, 0, panel1.Width, panel1.Height)) Dim pageaBounds As Rectangle = e.PageBounds e.Graphics.DrawImage(bmp, 10, 10) End Using End Sub
- Marqué comme réponse Orleandeux jeudi 4 juin 2020 20:31
-
Bonsoir
Merci Castorix31
excuse moi ou je n’ai pas compris
je ne voie pas le sub CenterToScreen()
- Marqué comme réponse Orleandeux jeudi 4 juin 2020 20:30
-
je ne voie pas le sub CenterToScreen()
C'est juste une API standard pour centrer la Form Form.CenterToScreen
- Marqué comme réponse Orleandeux jeudi 4 juin 2020 20:30
-
désoler et merci
- Marqué comme réponse Orleandeux jeudi 4 juin 2020 20:30
- Non marqué comme réponse Nina ZaekovaMicrosoft contingent staff, Moderator vendredi 19 juin 2020 06:29