0

How would I go about aligning my text to the right side using DrawString.

I want to have it look like this

______1 st

instead of

1______ st

note:

"st" is from a second drawstring

_ is used as placeholder for empty space, not existing in the project

If I use String.Format to add placeholders in front of the number it gets spaced correctly but I don't want the placeholders in front of it, When I tried it with the # in string format it simply placed it back to the left side.

So how would I go about placing the text on the right side?

What i've tried so far:

//the drawsting with 0 placeholders (gets the number on the right place but I want to remove the extra 0's)
e.Graphics.DrawString(String.Format("{0:0000000}", Convert.ToInt32(printAANT[itemsPrinted])), DefaultFont, Brushes.Black, distance, currentY);
//this just sets it to the left again
e.Graphics.DrawString(String.Format("{0:######0}", Convert.ToInt32(printAANT[itemsPrinted])), DefaultFont, Brushes.Black, distance, currentY);

And padLeft or using the format {0,-12:0} would both place the text more to the right and then draw the string on top of the "st".

maam27
  • 444
  • 3
  • 21
  • You didn't try enough. Many overloads for DrawString(), you need the one that takes StringFormat so you can specify StringAlignment.Far. Don't use Graphics.DrawString() to paint to the screen, use TextRenderer instead. – Hans Passant Apr 08 '15 at 11:09
  • It's not to put it on the screen it is for PrintDialog and i tried to set it using a overload but either it just doesnt work or i chose the wrong type – maam27 Apr 08 '15 at 11:10
  • If you already knew you needed to use a different overload then it was rather silly to post code that doesn't use it. Nothing anybody can do with "it doesn't work". – Hans Passant Apr 08 '15 at 11:18

0 Answers0