Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Please help me... i m not getting proper alignment for my text in c#.net... I'm posting snap of output along with its c#.net code... please correct me... thanks in advance

String drawString = "" + frmProperties.steel_maker;


// Create font and brush.
Font drawFont = new Font("Merchant Copy", 12F);
SolidBrush drawBrush = new SolidBrush(Color.Black);

// Create rectangle for drawing.
float x = 239;
float y = 490f;
float width = 110f;
float height = 60f;
RectangleF drawRect = new RectangleF(x, y, width, height);

// Draw rectangle to screen.
Pen blackPen = new Pen(Brushes.White);
// e.Graphics.DrawRectangle(blackPen, x, y, width, height);
e.Graphics.DrawRectangle(blackPen, x, y, width, height);

// Set format of string.
StringFormat drawFormat = new StringFormat();
drawFormat.Alignment = StringAlignment.Far;
drawFormat.LineAlignment = StringAlignment.Center;

e.Graphics.DrawString(drawString, drawFont, drawBrush, drawRect, drawFormat);


Output m getting as:
 Jindal Steel &
    Power Ltd.,
Chattisgarh,Well
known Steel-Maker

But Expected Output Should be some like:
Jindal Steel &
Power Ltd.,
Chattisgarh,Well
known Steel-Maker

Please Help
Posted
Updated 10-Feb-14 4:48am
v2

I solved it by myself :)

by simply changing
C#
drawFormat.Alignment = StringAlignment.Far;
drawFormat.LineAlignment = StringAlignment.Center;

to
C#
drawFormat.Alignment = StringAlignment.Near;
drawFormat.LineAlignment = StringAlignment.Near;
 
Share this answer
 
Change
C#
drawFormat.Alignment = StringAlignment.Far;
drawFormat.LineAlignment = StringAlignment.Center;

to
C#
drawFormat.Alignment = StringAlignment.Near;
drawFormat.LineAlignment = StringAlignment.Near;


[Edit] Looks like OP beat me to it. +5 for them.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900