By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,505 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,505 IT Pros & Developers. It's quick & easy.

commas underneath each other

P: n/a
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

Nov 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<sv*@pc.dk> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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

Nov 17 '05 #2

P: n/a
svm
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

Nov 17 '05 #3

P: n/a
This sounds like a job for MeasureString()!

http://msdn.microsoft.com/library/de...tringtopic.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
"sv*@pc.dk" wrote:
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

Nov 17 '05 #4

P: n/a
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
<sv*@pc.dk> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
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

Nov 17 '05 #5

P: n/a
svm
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...

Nov 17 '05 #6

P: n/a

<sv*@pc.dk> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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


Courier New is a TrueType fixed-width font. I am reading this email in that
font now.
David
Nov 17 '05 #7

P: n/a
I suggest using one of the fonts in which all the charcters are the same
width, such as Courier.

Nov 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.