How to draw reverse string?

  • Thread starter Thread starter Jerry
  • Start date Start date
J

Jerry

Hi,

I want to draw a reverse string, does anyone know how to implement it?
And I want to draw a vertical string, it can be implemented by setting
StringFormat.StringFormatFlags DirectionVertical, but it's not the effect I
expected. I want to get reverse vertical string, like the number of MS Word
vertical ruler. How to implement it?
 
How about like this.

\\\
Private Sub Form_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) _
Handles MyBase.Paint
Dim MyString As String = "1-2-3-4-5"
If CheckBox1.Checked Then
Dim MyChar() As Char = MyString.ToCharArray
Array.Reverse(MyChar)
MyString = New String(MyChar)
End If
Dim BufferSize As Size = e.Graphics.MeasureString(MyString, Font).ToSize
Dim Buffer As New Bitmap(BufferSize.Width, BufferSize.Height)
Dim g As Graphics = Graphics.FromImage(Buffer)
g.Clear(BackColor)
g.DrawString(MyString, Font, Brushes.Black, 0, 0)
Buffer.RotateFlip(RotateFlipType.Rotate270FlipNone)
e.Graphics.DrawImage(Buffer, 0, 0)
g.Dispose()
Buffer.Dispose()
End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Invalidate()
End Sub
///

p.s. You can rotate the graphics object instead of drawing to a bitmap
first, but I found that can cause odd behaviour on transparent child
controls of a transparent parent, so I now always draw to a bitmap and
rotate that.
 
If you're looking for some simple method like:
DrawReversedRotatedString(e.Graphics, MyString, Me.Font, x, y, 270)
then AFAIK no, not off the shelf.

The standard approach would be to translatetransform the graphics object,
and most of the time that method is acceptable, but I found that it caused
the graphics to be redrawn on transparent children of transparent
parentcontrols. In other words, what ever was painted at point(0,0) on the
transparent parent would be painted at point(0,0) of the transparent child.
At least that was the result on my custom controls, whereas drawing to
bitmap, rotating it and then drawing the bitmap to my controls did not have
this result.

If you mean to reverse the string then in Microsoft.VisualBasic there is a
strReverse method.
\\\
ReverseString = strReverse(MyString)
///
but no equivelant in C#.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


Jerry said:
Thank you!

Does MS provide any other ways to implement it?


"Mick Doherty"
<EXCHANGE#[email protected].[mdaudi100#ntlworld.com]>
дÈëÓʼþ
 
Back
Top