Click here to Skip to main content
15,891,375 members

Graphic System.Drawing Flipped Text

Nazim Iqbal asked:

Open original thread
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
Tags: Visual Basic

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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