anybody here can you give me an example on how to create
a text with mirror at the bottom.
tnx.
Printable View
anybody here can you give me an example on how to create
a text with mirror at the bottom.
tnx.
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
Could you translate into C Sharp code please.
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.
Tada!I even used the correct language. ;)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); }
Thanks, that is some slick code.
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.Quote:
Originally Posted by basti42
ok! i tried below and it works!
Font f = new Font(label1.Font.FontFamily, label1.Font.Size + 5);