Results 1 to 9 of 9

Thread: mirror text

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    mirror text

    anybody here can you give me an example on how to create
    a text with mirror at the bottom.

    tnx.
    *****************
    VB6,PHP,VS 2005

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: mirror text

    I'm not sure if there's another way but I don't think so. I think you'd have to use GDI+ to draw your text onto an Image and then call that image's RotateFlip method to create the mirror image.
    vb.net Code:
    1. Private textImage As Image
    2. Private mirrorImage As Image
    3.  
    4. Private Sub Form1_Load(ByVal sender As Object, _
    5.                        ByVal e As EventArgs) Handles MyBase.Load
    6.     Dim text As String = "Hello World"
    7.     Dim textSize As Size
    8.  
    9.     Using g As Graphics = Me.CreateGraphics()
    10.         textSize = Size.Round(g.MeasureString(text, Me.Font))
    11.     End Using
    12.  
    13.     Me.textImage = New Bitmap(textSize.Width, textSize.Height)
    14.  
    15.     Using g As Graphics = Graphics.FromImage(Me.textImage)
    16.         g.DrawString(text, Me.Font, Brushes.Black, 0, 0)
    17.     End Using
    18.  
    19.     Me.mirrorImage = DirectCast(Me.textImage.Clone(), Image)
    20.     Me.mirrorImage.RotateFlip(RotateFlipType.RotateNoneFlipY)
    21. End Sub
    22.  
    23. Private Sub Form1_Paint(ByVal sender As Object, _
    24.                         ByVal e As PaintEventArgs) Handles Me.Paint
    25.     e.Graphics.DrawImage(Me.textImage, Point.Empty)
    26.     e.Graphics.DrawImage(Me.mirrorImage, 0, Me.textImage.Height)
    27. End Sub
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: mirror text

    Could you translate into C Sharp code please.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: mirror text

    B*gger! That's the second time today I've forgetten I was in the C# forum and posted VB code. That said, there are lots of code converters on the Web and there's also Instant C# from Tangible Software.

    Anyway, it occurred to me after I shut down last night that there may well be another way. You can transform the Graphics object that does the drawing so you might be able to just call DrawString and avoid the use of an Image altogether. I'll give that a try and see if it works.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: mirror text

    Tada!
    CSharp Code:
    1. private void Form1_Paint(object sender, PaintEventArgs e)
    2. {
    3.     Point normalLocation = new Point(10, 10);
    4.  
    5.     // Draw the normal string.
    6.     e.Graphics.DrawString("Hello World",
    7.                           this.Font,
    8.                           Brushes.Black,
    9.                           normalLocation);
    10.  
    11.     // Get the size of the normal string so we know where to draw the mirror image.
    12.     Size normalSize = Size.Round(e.Graphics.MeasureString("Hello World",
    13.                                                           this.Font));
    14.  
    15.     // Flip the Graphics object's frame of reference in the vertical direction.
    16.     e.Graphics.ScaleTransform(1f, -1f);
    17.  
    18.     // The mirror image will be drawn at the same X position but below the bottom of the normal text.
    19.     // Remember that up is down now, so if we want to push the text down the form, that is now the negative Y direction.
    20.     // The 10 is arbitrary to leave a gap between the two strings.  You can increase or decrease it to taste.
    21.     Point mirrorLocation = new Point(normalLocation.X,
    22.                                      -(normalLocation.Y + normalSize.Height + 10));
    23.  
    24.     // Draw the mirror image.
    25.     e.Graphics.DrawString("Hello World",
    26.                           this.Font,
    27.                           Brushes.Black,
    28.                           mirrorLocation);
    29. }
    I even used the correct language.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: mirror text

    Thanks, that is some slick code.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: mirror text

    tnx jmc...
    what about how increase the font size?
    *****************
    VB6,PHP,VS 2005

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: mirror text

    Quote Originally Posted by basti42
    tnx jmc...
    what about how increase the font size?
    In my example code I specified this.Font when calling DrawString, so it just uses the form's default font. If you want to use a different font then just create your own Font object and pass that to DrawString.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: mirror text

    ok! i tried below and it works!
    Font f = new Font(label1.Font.FontFamily, label1.Font.Size + 5);
    *****************
    VB6,PHP,VS 2005

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width