commas underneath each other

  • Thread starter Thread starter svm
  • Start date Start date
S

svm

Hi!

I'm in the process of creating an invoice-generating program in C#...

I've already written the code to produce the page using a
PrintDocument, but graphics.DrawString only accepts truetype fonts, so
i can't just use spaces (" ") to line up commas...

Basically, i would like to do something like this:
(In Denmark we use comma as decimal seperator...)

[Product name] [Price]
Some product 28,00
Another product 10,00
---------------------------
Subtotal 38,00

I hope you know what I mean, any ideas that might help me?
Thanks in advance
-Steffen Madsen
 
Steffen,

Since you know that numbers will have a constant width, why not just
position the numbers absolutely on the print document? Instead of using
spaces, just determine the width of the numbers and do the calculations to
right align them?

Hope this helps.
 
Hi!

I'm in the process of creating an invoice-generating program in C#...

I've already written the code to produce the page using a
PrintDocument, but graphics.DrawString only accepts truetype fonts, so
i can't just use spaces (" ") to line up commas...

Basically, i would like to do something like this:
(In Denmark we use comma as decimal seperator...)

[Product name] [Price]
Some product 28,00
Another product 10,00

Courier New is a TrueType fixed-width font. I am reading this email in that
font now.


David
 
OK, I think I'll use MeasureString().... and just right align them.
I just hoped for something simple, where I didn't need to do much... :)

Well, thanks for your input....

-Steffen Madsen
 
This sounds like a job for MeasureString()!

http://msdn.microsoft.com/library/d...temdrawinggraphicsclassmeasurestringtopic.asp

Taking arguments very similar to DrawString(), MeasureString() returns a
SizeF structure that tells you what the size required for the string to be
drawn as specified.

Why is this useful? If you break up your drawing tasks into different parts,
you can draw your product names just as you were before and do a little
string manipulation on the prices...

Draw an imaginary line on your form where you want your prices to be
centered from... you’d start by measuring the size of the price to the right
of the separator and subtracting the width portion of the size returned from
the position of your imaginary line and start drawing the left portion of the
price at the resulting x axis value.

You would do a similar thing for the separator and everything to the right
of it, only it would when drawn be started on the imaginary line.

This example does assume that the font you are using is not of a uniform
width... if it is... you can do what I mentioned above to the entire string,
only your imaginary line would be located where you want all of the strings
to end.

Brendan
 
Steffen,

That's pretty simple, I mean, all you have to do is call measure string,
and then subtract that from the x coordinate that you are going to
right-align it all with.
 
okay okay, I got it... :)

Taking in account that it is kinda late here in the evening, so my
brain was just on hold I guess...

Thank you everyone - I must say I didn't expect answers to come so
quickly.

Ps: I got it fixed now and it looks A LOT better...
 
I suggest using one of the fonts in which all the charcters are the same
width, such as Courier.
 
Back
Top