471,319 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

DrawString right aligned

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)

Jan 21 '06 #1
4 11831
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.

--
Tim Wilson
..NET Compact Framework MVP

"GTi" <tu****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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)

Jan 22 '06 #2
GTi
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 ?

Jan 22 '06 #3
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.

--
Tim Wilson
..NET Compact Framework MVP

"GTi" <tu****@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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 ?

Jan 22 '06 #4
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/de...oLeftTopic.asp)
and its interaction with child control's HorizontalAlignment
properties.

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

Jan 22 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Marek Mand | last post: by
1 post views Thread by David Lindgren | last post: by
6 posts views Thread by Sam Sungshik Kong | last post: by
4 posts views Thread by Sin Jeong-hun | last post: by
9 posts views Thread by kynos | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.