Rotate text on PrintPreview using C# and VB.Net in Windows Application

Last Reply 7 months ago By dharmendr

Posted 7 months ago

Hi 

Working in vb.net and using printDcoument with PrintPreviewDialog 

Everything working fine, but text I want to rotate my text on print preview 

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If CheckBox1.Checked = True Then
            PrintDocument1.DefaultPageSettings.Landscape = True
        End If
        If PrintPreviewDialog1.ShowDialog = DialogResult.OK Then

            PrintDocument1.Print()
        End If
    End Sub

    Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        ' TextBox1.CreateGraphics.RotateTransform(90)

        e.Graphics.DrawString(TextBox1.Text, New Font("Time New Romans", 14, FontStyle.Bold), Brushes.Black, New PointF(300, 400))


        e.Graphics.DrawString(TextBox2.Text, New Font("Time New Romans", 14, FontStyle.Bold), Brushes.Black, New PointF(300, 430))
        'ate 45° clockwise
        e.Graphics.RotateTransform(90)

        e.Graphics.ResetTransform()

    End Sub

 

You are viewing reply posted by: dharmendr 7 months ago.
Posted 7 months ago

Hi Shahzad786,

Check this example. Now please take its reference and correct your code.

Code

C#

private void button1_Click(object sender, EventArgs e)
{
    PrintDocument1.DefaultPageSettings.Landscape = true;
    PrintPreviewDialog1.Document = PrintDocument1;
    PrintPreviewDialog1.PrintPreviewControl.Zoom = 1;
    PrintPreviewDialog1.ShowDialog();
}

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    e.Graphics.DrawString(TextBox1.Text, new Font("Time New Romans", 14, FontStyle.Bold), Brushes.Black, new PointF(200, 400));
    e.Graphics.RotateTransform(90);
    e.Graphics.DrawString(TextBox2.Text, new Font("Time New Romans", 14, FontStyle.Bold), Brushes.Red, new PointF(300, -400));
}

VB.Net

Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
    PrintDocument1.DefaultPageSettings.Landscape = True
    PrintPreviewDialog1.Document = PrintDocument1
    PrintPreviewDialog1.PrintPreviewControl.Zoom = 1
    PrintPreviewDialog1.ShowDialog()
End Sub

Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    e.Graphics.DrawString(TextBox1.Text, New Font("Time New Romans", 14, FontStyle.Bold), Brushes.Black, New PointF(200, 400))
    e.Graphics.RotateTransform(90)
    e.Graphics.DrawString(TextBox2.Text, New Font("Time New Romans", 14, FontStyle.Bold), Brushes.Red, New PointF(300, -400))
End Sub

Screenshot