|
-
December 4th, 2009, 12:30 AM
#1
Text Alignment
Hi,
How to align string to Left, Right, Center and Middle? I have done other alignment like middle center,middle left,middle right, top left etc using StringAligment.
Help me to alignment string in Left, Right, Center and Middle.
Code:
StringFormat objStringFormat = new StringFormat();
objStringFormat.Alignment = StringAlignment.Center;
objStringFormat.LineAlignment = StringAlignment.Center;
Thank you
Saravana
-
December 4th, 2009, 06:15 AM
#2
Re: Text Alignment
Where are you trying to align your text? I mean, is it a UserControl you built yourself and want to render the text aligned somewhere on your control? Or is it a RichTextBox ?
StringFormat is used to give DrawString (of the Graphics class) formatting flags.
This will draw a string in the middle of a bitmap:
Code:
Graphics g = Graphics.FromImage(myBmp);
StringFormat strFmt = new StringFormat();
strFmt.Alignment = StringAlignment.Center;
strFmt.LineAlignment = StringAlignment.Center;
Rectangle rect = new Rectangle(0,0,myBmp.Width,myBmp.height);
g.DrawString("asdf",SystemBrushes.WindowText,someFont,rect,strFmt);
I might have the DrawString parameters wrong, haven't fired up Visual Studio yet
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|