Click here to Skip to main content
15,885,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I need Help
I Flipped Text like a mirror image.

But line brake are not coming, all text from textbox showed in one line
Put Text in text box, while mine is come from database.

Here is my code....HELP please

VB
Imports System.Drawing.Drawing2D
Imports System.Drawing


Public Class Form1


    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint


        ' Draw the text and the surrounding rectangle START.
        Dim text1 As String = RichTextBox1.Text
        Dim font1 As New Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Point)
        Try
            Dim rect1 As New Rectangle(10, 10, 1000, 140)

            ' Create a StringFormat object with the each line of text, and the block 
            ' of text centered on the page. 
            Dim stringFormat As New StringFormat()
            stringFormat.Alignment = StringAlignment.Center
            stringFormat.LineAlignment = StringAlignment.Center


            ' Draw the text and the surrounding rectangle.
            e.Graphics.DrawString(text1, font1, Brushes.Blue, rect1, stringFormat)
            e.Graphics.DrawRectangle(Pens.Black, rect1)

        Finally
            font1.Dispose()
        End Try
        ' Draw the text and the surrounding rectangle END.


        '' FLIP TEXT ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ' Draw Flipped Text the text surrounding rectangle START.

        Using the_font As New Font("Arial", 20, FontStyle.Bold, GraphicsUnit.Point)

            DrawFlippedText(e.Graphics, the_font, Brushes.Black, 10, 10, RichTextBox1.Text, True, False)

            Dim txt_size As SizeF
            txt_size = e.Graphics.MeasureString(RichTextBox1.Text, the_font)
            e.Graphics.DrawRectangle(Pens.Red, 10, 10, txt_size.Width, txt_size.Height)

        End Using

        ' Draw Flipped Text the text surrounding rectangle END.
        '' FLIP TEXT ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    End Sub

    Public Sub DrawFlippedText(ByVal gr As Graphics, ByVal the_font As Font, ByVal the_brush As Brush, ByVal x As Integer, ByVal y As Integer, ByVal txt As String, ByVal flip_x As Boolean, ByVal flip_y As Boolean)

        ' Save the current graphics state.
        Dim state As GraphicsState = gr.Save()

        ' Set up the transformation.
        Dim scale_x As Integer = IIf(flip_x, -1, 1)
        Dim scale_y As Integer = IIf(flip_y, -1, 1)
        gr.ResetTransform()
        gr.ScaleTransform(scale_x, scale_y)


        ' Figure out where to draw.
        Dim txt_size As SizeF = gr.MeasureString(txt, the_font)

        If flip_x Then x = -x - RichTextBox1.Size.Width
        If flip_y Then y = -y - RichTextBox1.Size.Height


        ' Draw.
        gr.DrawString(txt, the_font, the_brush, x, y)

        ' Restore the original graphics state.
        gr.Restore(state)

    End Sub

End Class
Posted
Comments
Just eg 24-Feb-13 23:59pm    
no problem with your code.
i have replace control RichtextBox1 with TextBox1 (multiline = true)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900