| | |
StringFormat
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jun 2008
Posts: 58
Reputation:
Solved Threads: 9
Hello,
I'm having some very confusing problems with the StringFormat class. I'm hoping someone will know what's going on.
I want to draw text right-to-left. It's multiple lines so I figured using the StringFormat class was an easy way to handle that, I declare it as:
Then i pass it along to the DrawString function in Graphics.
The problem is that when the string being drawn ends with a non-alphanumeric character (!, ?, >, ., etc.) it gets draw on the wrong side of the string
For example, "hello!" is being drawn as "!hello"
I tried messing around with the properties of StringFormat but it's not helping, anyone have any ideas?
I'm having some very confusing problems with the StringFormat class. I'm hoping someone will know what's going on.
I want to draw text right-to-left. It's multiple lines so I figured using the StringFormat class was an easy way to handle that, I declare it as:
C# Syntax (Toggle Plain Text)
StringFormat f = new StringFormat(StringFormatFlags.DirectionRightToLeft);
Then i pass it along to the DrawString function in Graphics.
The problem is that when the string being drawn ends with a non-alphanumeric character (!, ?, >, ., etc.) it gets draw on the wrong side of the string
For example, "hello!" is being drawn as "!hello"
I tried messing around with the properties of StringFormat but it's not helping, anyone have any ideas?
Visual C# Kicks - Free C# code resources and articles.
It might have something to do with interfering international settings(eg Arabic is written from riht to left) because other Flags as DirectionVertical behave as expected. It might be that it is just a plain bug -->one address : Microsoft.
THe only solution I see for the moment if you want to do this : revert the string
THe only solution I see for the moment if you want to do this : revert the string
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Jun 2008
Posts: 58
Reputation:
Solved Threads: 9
Thanks for the input. You gave me an idea and turns out the thing is reversing the string, but not really reversing it.
"hello!?" comes out as "?!hello"
So basically it reverses the order of the characters, except if they are alphanumeric. I can't for the life of me imagine when you would want to do that (maybe for some other language?)
Turns out a better way to do it is to create a plain simple StringFormat class and set the alignment property instead:
That way it doesn't reverse anything and just aligns everything off to the right.
"hello!?" comes out as "?!hello"
So basically it reverses the order of the characters, except if they are alphanumeric. I can't for the life of me imagine when you would want to do that (maybe for some other language?)
Turns out a better way to do it is to create a plain simple StringFormat class and set the alignment property instead:
C# Syntax (Toggle Plain Text)
StringFormat f = new StringFormat(); f.Alignment = StringAlignment.Far;
That way it doesn't reverse anything and just aligns everything off to the right.
Visual C# Kicks - Free C# code resources and articles.
![]() |
Similar Threads
- Need help with text (VB.NET)
- To print Html page using PrintDialog and Print Document (VB.NET)
- Problems from string to int array (C)
- Printing problem (VB.NET)
- Printing problems (C#)
Other Threads in the C# Forum
- Previous Thread: How to GetPixel from Bitmap?
- Next Thread: Simple <Form> data error
Views: 1910 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access algorithm array barchart bitmap box button buttons c# chat check checkbox class client code color combobox control conversion csharp custom database datagridview dataset datetime degrees draganddrop drawing encryption enum excel file files form format forms ftp function gcd gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






