Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionOption Strict On Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'déclaration d'un document à imprimer Dim doc As New Printing.PrintDocument 'impression en paysage doc.DefaultPageSettings = New Printing.PageSettings() With {.Landscape = True} 'valeur de textbox1 TextBox1.Text = "Texte blanc sur fond bleu" 'abonnement à l'événement PrintPage AddHandler doc.PrintPage, AddressOf ConstruitDoc 'declaration d'une prévisualisation avant impression Dim preview As New PrintPreviewDialog preview.Document = doc 'affichage de la prévisualisation If preview.ShowDialog = DialogResult.OK Then 'si ok alors impression doc.Print() End If End Sub Private Sub ConstruitDoc(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs) 'dessin d'un rectangle bleu plein e.Graphics.FillRectangle(Brushes.Blue, New Rectangle(200, 200, 210, 30)) 'texte reprenant le contenu de textbox1 e.Graphics.DrawString( _ TextBox1.Text, _ New Font("Arial", 12, FontStyle.Italic Or FontStyle.Underline), _ Brushes.White, _ New Point(205, 205)) e.HasMorePages = False End Sub End Class
Private Sub ConstruitDoc(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs) 'dessin d'un rectangle bleu plein e.Graphics.FillRectangle(Brushes.Blue, New Rectangle(200, 200, 250, 300)) 'texte reprenant le contenu de textbox1 e.Graphics.DrawString( _ TextBox1.Text, _ New Font("Arial", 12, FontStyle.Italic Or FontStyle.Underline), _ Brushes.White, _ New Rectangle(200, 200, 250, 300), _ New StringFormat() With {.LineAlignment = StringAlignment.Center}) e.HasMorePages = False End Sub
Private Sub ConstruitDoc(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs) 'rectangle cible (augmenter la hauteur 400 si besoin) Dim Cible As New Rectangle(200, 200, 250, 400) 'font utilisée (à changer bien sur) Dim MaFont As New Font("Arial", 15, FontStyle.Regular) 'format d'affichage ('center' pour centrer dans le rectangle cible) Dim MonFormat As New StringFormat() With {.LineAlignment = StringAlignment.Center} 'graphicPath Dim MonGrPath As New GraphicsPath MonGrPath.AddString(TextBox1.Text, _ MaFont.FontFamily, CInt(FontStyle.regular), _ Cible.Height, New PointF(0, 0), MonFormat) Dim MonGrRect As RectangleF = MonGrPath.GetBounds Dim CiblePts() As PointF = { _ New PointF(Cible.Left, Cible.Top), _ New PointF(Cible.Right, Cible.Top), _ New PointF(Cible.Left, Cible.Bottom) _ } e.Graphics.FillRectangle(Brushes.YellowGreen, Cible) e.Graphics.Transform = New Matrix(MonGrRect, CiblePts) e.Graphics.SmoothingMode = SmoothingMode.AntiAlias e.Graphics.FillPath(Brushes.Blue, MonGrPath) e.Graphics.DrawPath(Pens.Blue, MonGrPath) e.Graphics.ResetTransform() e.Graphics.DrawRectangle(Pens.Black, Cible) e.HasMorePages = False End Sub