|
-
Jul 12th, 2008, 05:19 AM
#1
Thread Starter
Hyperactive Member
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
-
Jul 12th, 2008, 06:58 AM
#2
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:
Private textImage As Image Private mirrorImage As Image Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As EventArgs) Handles MyBase.Load Dim text As String = "Hello World" Dim textSize As Size Using g As Graphics = Me.CreateGraphics() textSize = Size.Round(g.MeasureString(text, Me.Font)) End Using Me.textImage = New Bitmap(textSize.Width, textSize.Height) Using g As Graphics = Graphics.FromImage(Me.textImage) g.DrawString(text, Me.Font, Brushes.Black, 0, 0) End Using Me.mirrorImage = DirectCast(Me.textImage.Clone(), Image) Me.mirrorImage.RotateFlip(RotateFlipType.RotateNoneFlipY) End Sub Private Sub Form1_Paint(ByVal sender As Object, _ ByVal e As PaintEventArgs) Handles Me.Paint e.Graphics.DrawImage(Me.textImage, Point.Empty) e.Graphics.DrawImage(Me.mirrorImage, 0, Me.textImage.Height) End Sub
-
Jul 12th, 2008, 11:19 AM
#3
Hyperactive Member
Re: mirror text
Could you translate into C Sharp code please.
-
Jul 12th, 2008, 08:24 PM
#4
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.
-
Jul 12th, 2008, 09:19 PM
#5
Re: mirror text
Tada!
CSharp Code:
private void Form1_Paint(object sender, PaintEventArgs e) { Point normalLocation = new Point(10, 10); // Draw the normal string. e.Graphics.DrawString("Hello World", this.Font, Brushes.Black, normalLocation); // Get the size of the normal string so we know where to draw the mirror image. Size normalSize = Size.Round(e.Graphics.MeasureString("Hello World", this.Font)); // Flip the Graphics object's frame of reference in the vertical direction. e.Graphics.ScaleTransform(1f, -1f); // The mirror image will be drawn at the same X position but below the bottom of the normal text. // Remember that up is down now, so if we want to push the text down the form, that is now the negative Y direction. // The 10 is arbitrary to leave a gap between the two strings. You can increase or decrease it to taste. Point mirrorLocation = new Point(normalLocation.X, -(normalLocation.Y + normalSize.Height + 10)); // Draw the mirror image. e.Graphics.DrawString("Hello World", this.Font, Brushes.Black, mirrorLocation); }
I even used the correct language.
-
Jul 13th, 2008, 12:43 AM
#6
Hyperactive Member
Re: mirror text
Thanks, that is some slick code.
-
Jul 13th, 2008, 07:20 PM
#7
Thread Starter
Hyperactive Member
Re: mirror text
tnx jmc...
what about how increase the font size?
*****************
VB6,PHP,VS 2005
-
Jul 13th, 2008, 07:49 PM
#8
Re: mirror text
 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.
-
Jul 13th, 2008, 08:21 PM
#9
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|