StringFormatFlags.DirectionRightToLeft

M

Marc Pelletier

Hello all,

I've found several posts that indicate the DirectionRightToLeft flag is
intended for right to left alphabets and shouldn't be used for
justification, but in my testing I've found that it does a better job of
right justifying text than the alternative. In the function below I draw
some text in four possible combinations of StringAlignment (Near and Far)
and Direction (RightToLeft and nothing, which is LeftToRight). What I've
found is that DirectionRightoleft and Far gives the same result (left
alignment) as lefttoright and Near. But DirectionRighttoLeft and Near does
a better job of right alignment than Lefttoright and Far.

Can anyone explain to me what the difference between these settings is and
why I shouldn't use RightToLeft for right justification?

thanks

Marc Pelletier


public void TestLabel( int x, int y, string value )
{
Pen redPen = new Pen( new SolidBrush( Color.Red ) );
redPen.Width = 1.0F;
SolidBrush blackBrush = new SolidBrush( Color.Black );
Font labelFont = new Font("Arial", 10);
StringFormat labelFormat = new StringFormat(
StringFormatFlags.DirectionRightToLeft );
labelFormat.Alignment = StringAlignment.Near;
g.DrawString(value, labelFont, blackBrush, new Point( x, y ),labelFormat
);
g.DrawLine( redPen, x, y, x, y+1 );
labelFormat.Alignment = StringAlignment.Far;
g.DrawString(value, labelFont, blackBrush, new Point( x, y+10
),labelFormat );
g.DrawLine( redPen, x, y+10, x, y+11 );
labelFormat = new StringFormat( );
labelFormat.Alignment = StringAlignment.Near;
g.DrawString(value, labelFont, blackBrush, new Point( x+100, y
),labelFormat );
g.DrawLine( redPen, x+100, y, x+100, y+1 );
labelFormat.Alignment = StringAlignment.Far;
g.DrawString(value, labelFont, blackBrush, new Point( x+100, y+10
),labelFormat );
g.DrawLine( redPen, x+100, y+10, x+100, y+11 );
}
 
M

Marc Pelletier

Can anyone explain to me what the difference between these settings is
and why I shouldn't use RightToLeft for right justification?

Well, I guess I can now. I'm sure there are other side effects, but when
using RightToLeft to display a negative number the negative sign is
displayed on the right side of the text. So -1.2 would be written as 1.2-,
which doesn't do it for me.

cheers

Marc Pelletier
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top