473,507 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

commas underneath each other

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
7 1401
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
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
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
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
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

<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
I suggest using one of the fonts in which all the charcters are the same
width, such as Courier.

Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3033
by: Roger Shrubber | last post by:
I have a page with images that the user can drag from one frame to another. I need them to see a "ghost image" of the image they are dragging, while the original stays put. I use the onmousemove...
9
3745
by: Marek Mänd | last post by:
<style type="text/css"> q:after{content:',"'} </style> <q>This will be the shame of CSS</q> claimed Marek Mänd and added that <q>consumers expect to create generated content via CSS where there...
22
13727
by: ineedyourluvin1 | last post by:
Hello all! I've been looking for a way to strip characters from strings such as a comma. This would be great for using a comma as a delimiter. I show you what I have right now. ...
7
8293
by: AES | last post by:
Encountered a URL containing a comma the other day -- the first time I've ever noticed that, so far as I can recall. It worked fine, however, and I gather commas are legal in URLs. Out of...
1
1057
by: Wolfgang | last post by:
In VC or VC++, suppose I have a simple window (a form). Is it possible from that window to "see" what's underneath a particular pixel? Basically, I want to "import" some pixels underneath my...
4
2477
by: striker | last post by:
I have a comma delimited text file that has multiple instances of multiple commas. Each file will contain approximatley 300 lines. For example: one, two, three,,,,four,five,,,,six one, two,...
5
3987
by: hprYeV | last post by:
I have done a reasonable amount of programming in C++, but the other day I was talking to someone after a lecture in a course on Java who said that they had not been used to the syntax of the Java...
9
8811
by: conspireagainst | last post by:
I'm having quite a time with this particular problem: I have users that enter tag words as form input, let's say for a photo or a topic of discussion. They are allowed to delimit tags with spaces...
5
4740
by: Robert Dodier | last post by:
Hello, I'd like to split a string by commas, but only at the "top level" so to speak. An element can be a comma-less substring, or a quoted string, or a substring which looks like a function...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7110
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5041
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.