DrawString right aligned

  • Thread starter Thread starter GTi
  • Start date Start date
G

GTi

This must be the simplest question on the web.
How can I right align text with DrawString ?

Normal (left aligned):
1234567890
123456789
12345678
1234567
123456
12345
1234
123
12
1

Right aligned:
1234567890
123456789
12345678
1234567
123456
12345
1234
123
12
1

(it may not look right on some readers)
 
Use one of the overloads of the DrawString method that accepts a
StringFormat and ensure that the Alignment property of the StringFormat
instance is set to Far.
 
Yeeeeh -
Why do they have to change it to near / far ???
Whats wrong with left/right and top/bottom?
Only to make old dogs more confused ?
 
The StringFormat class also has a LineAlignment property that uses the
StringAlignment enum. The LineAlignment is the vertical alignment. So it
would be top, middle, and bottom. However, by calling the enum values near,
center, and far they can reuse this enum across both alignment properties.
Used in the context of the LineAlignment property the "far" value would mean
bottom. There is also the notion of left-to-right versus right-to-left
layout. So based on the layout, "far" means the opposite side, or far side,
from the origin position, which could be left or right depending on the
layout. I'm in no way attempting to defend this decision, nor am I stating
that these are the reasons why it was done. I'm merely stating that these
might be possible reasons for this naming decision.
 
I believe "near" and "far" were chosen to provide compatibility with
right-to-left (RTL) languages such as Hebrew and Arabic. For example,
"near" means to align the text to the left edge in a Left-to-right
language, and align to the right on a RTL language.

However, this use of near and far is not consistent across the .NET
platform; see Control.RightToLeft property
(http://msdn.microsoft.com/library/d...mWindowsFormsControlClassRightToLeftTopic.asp)
and its interaction with child control's HorizontalAlignment
properties.

-- Tim Scott
http://geekswithblogs.net/tscott
 
Back
Top