To draw text at an angle, use the Graphics object and create a subroutine to rotate text.
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Me.C1PrintDocument1.StartDoc() Me.C1PrintDocument1.RenderBlockGraphicsBegin() ' Declare the graphics object. Dim g As System.Drawing.Graphics g = Me.C1PrintDocument1.CurrentBlockGraphics Dim fontb = New Font("Arial", 32, FontStyle.Bold) ' Subroutine to alter text angle. RotateText(g, fontb, "Hello World", -45, Brushes.CadetBlue, -150, 150) Me.C1PrintDocument1.RenderBlockGraphicsEnd() Me.C1PrintDocument1.EndDoc() |
To write code in C#
C# |
Copy Code
|
---|---|
this.c1PrintDocument1.StartDoc(); this.c1PrintDocument1.RenderBlockGraphicsBegin(); // Declare the graphics object. System.Drawing.Graphics g; g = this.c1PrintDocument1.CurrentBlockGraphics; Font fontb = new Font("Arial", 12, FontStyle.Bold); // Subroutine to alter text angle. RotateText(g, fontb, "Hello World", -45, Brushes.CadetBlue, 10, 100); this.c1PrintDocument1.RenderBlockGraphicsEnd(); this.c1PrintDocument1.EndDoc(); |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Public Sub RotateText(ByVal g As Graphics, ByVal f As Font, ByVal s As String, ByVal angle As Single, ByVal b As Brush, ByVal x As Single, ByVal y As Single) If angle > 360 Then While angle > 360 angle = angle - 360 End While ElseIf angle < 0 Then While angle < 0 angle = angle + 360 End While End If ' Create a matrix and rotate it n degrees. Dim myMatrix As New System.Drawing.Drawing2D.Matrix myMatrix.Rotate(angle, Drawing2D.MatrixOrder.Append) ' Draw the text to the screen after applying the transform. g.Transform = myMatrix g.DrawString(s, f, b, x, y) End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
public void RotateText(Graphics g, Font f, string s, Single angle, Brush b, Single x, Single y) { if (angle > 360) { while (angle > 360) { angle = angle - 360; } } else if (angle < 0) { while (angle < 0) { angle = angle + 360; } } // Create a matrix and rotate it n degrees. System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix(); myMatrix.Rotate(angle, System.Drawing.Drawing2D.MatrixOrder.Append); // Draw the text to the screen after applying the transform. g.Transform = myMatrix; g.DrawString(s, f, b, x, y); } |
The text you added appears at a 45 degree angle: