Print Using

  • Thread starter Thread starter Al Jones
  • Start date Start date
A

Al Jones

Okay, this is dumb....

In gwbasic I can print using "#####.####"; 12.987654 and that produces
,,,12.9876 (commas for spaces). I've looked at buildstring, and tostring
but nothing I've seen gives me the ability to format with a non-currency
number position to the right of the decimal ... would someone please tell
me what I'm not seeing!
 
Dim decNumber As Decimal = 12.987654
Dim strFormat As String = Format(decNumber, "#####.####")
MessageBox.Show(strFormat)
 
Damn, I knew it was going to be something simple, but as many ways as I
looked up format (string format, numeric format, number format, etc) I
guess I didn't bother with just 'format'.

Thanks //al
 
Okay, now how do I get it to preserve leading spaces and while I'm begging
(I am begging, right?) how to force it to give me some 0's - not leading.
Okay, I've got the zero's (##0.0000) but this report wanders all over the
page ... help!
 
Al,
The way I line things up is to define a method that prints to the left
of a given position by measuring the printed string and then offsetting the
print position by the approriate amount. I use Graphics.MeasureString using
one of the formats containing a StringFormat.GenericTypographic object.
This produces a report that is aligned correctly visually. If you were to
be really picky in alignment you might want to use MeasureCharacterRanges
instead. See numerous posts in microsoft.public.dotnet.framework.drawing
about MeasureString and accuracy.
Note that you can also allow for negative amounts shown in parenthesis
by offsetting the result of the x calculation back to the right by the width
of a closing parenthesis if this is relavent to your display needs.

psuedo code which may not be quite VB format
Sub PrintToTheLeftOf(String s, Single x, Single y, Font aFont, Brush aBrush,
Graphics aGraphics)
dim deltax as Single
deltax = aGraphics.MeasureString(s, aFont, new Point(x, y),
StringFormat.GenericTypographic).Width
aGraphics.DrawString(s, aFont, aBrush, x - deltax, y,
StringFormat.GenericTypographic)
End Sub

Ron Allen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top