我有這樣的事情:如何對齊貨幣的點在打印過程中
Public Function ItemsToBePrinted()
Dim p_dt As DataTable = Model_Query(2)
Dim p_str As String = ""
Dim StringToPrint As String = ""
For Each drow As DataRow In p_dt.Rows
Dim str_itemName As New String(drow.Item("item_name").ToString)
Dim str_itemQty As New String(drow.Item("item_qty").ToString)
Dim str_itemUnitPrice As New String(drow.Item("item_unitprice").ToString)
Dim str_itemDisc As New String(drow.Item("item_disamt").ToString)
Dim str_itemTotalAmt As New String(drow.Item("item_totamt").ToString)
Dim lineLen1 As String = str_itemName.Length
Dim lineLen2 As String = str_itemQty.Length
Dim lineLen3 As String = str_itemUnitPrice.Length
Dim lineLen4 As String = str_itemDisc.Length
Dim spcLen1 As New String(" "c, 20 - lineLen1)
Dim spcLen2 As New String(" "c, 5 - lineLen2)
Dim spcLen3 As New String(" "c, 5 - lineLen3)
Dim spcLen4 As New String(" "c, 8 - lineLen4)
If drow.Item("item_disamt") = 0 Then
StringToPrint = $"{str_itemName}{spcLen1}{str_itemQty}{spcLen2}{str_itemUnitPrice}{spcLen3}{spcLen4}{str_itemTotalAmt}"
Else
StringToPrint = $"{str_itemName}{spcLen1}{str_itemQty}{spcLen2}{str_itemUnitPrice}{spcLen3}{str_itemDisc}{spcLen4}{str_itemTotalAmt}"
End If
p_str &= StringToPrint & Environment.NewLine
Next
Return p_str
End Function
Public Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim p_font As Font = New Font("Consolas", 10)
e.Graphics.DrawString(PrintItemHeader(), p_font, Brushes.Black, 2 * 8, 305)
e.Graphics.DrawLine(p_pen, 16, 340, 350, 340)
e.Graphics.DrawString(ItemsToBePrinted(), p_font, Brushes.Black, 2 * 8, 345)
目前即時通訊使用的spcLen計數的空間,使他們左對齊,但我不知道如何更改爲右對齊...
這裏是輸出:
我該如何調整這樣的點?所有的數據都將調整到右,除了商品編號
Item Code Qty Unit Disc Amount
Price
----------------------------------------------
XXXX 33 4.70 155.10
XXXX 2 3.00 6.00
XXXX 2 9.00 1.80 16.20
XXXX 1 7.50 7.50
XXXX 11 12.00 10.00 122.00
@Steve我覺得Consolas是一個固定寬度的字體? http://graphicdesign.stackexchange.com/questions/13148/which-fonts-have-the-same-width-for-every-character – vbnewbie
正確,我沒有看到字體聲明 – Steve