943,740 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 4245
  • C# RSS
Jan 3rd, 2009
0

StringFormat

Expand Post »
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:

C# Syntax (Toggle Plain Text)
  1. 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?
Similar Threads
Reputation Points: 11
Solved Threads: 9
Junior Poster in Training
vckicks is offline Offline
58 posts
since Jun 2008
Jan 3rd, 2009
0

Re: StringFormat

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
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,736 posts
since Oct 2008
Jan 3rd, 2009
0

Re: StringFormat

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:

C# Syntax (Toggle Plain Text)
  1. StringFormat f = new StringFormat();
  2. f.Alignment = StringAlignment.Far;

That way it doesn't reverse anything and just aligns everything off to the right.
Reputation Points: 11
Solved Threads: 9
Junior Poster in Training
vckicks is offline Offline
58 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: How to GetPixel from Bitmap?
Next Thread in C# Forum Timeline: Simple <Form> data error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC