簡體   English   中英

vb.net打印datagridview列對齊

[英]vb.net print datagridview column alignment

我的網格顯示的前三列左對齊,后四列右對齊。

使用此代碼e.Graphics.DrawString(Stock.gdColours(j, i).Value, f, Brushes.Black, x, y + 4)

所有列均左對齊打印。 因為我需要第3列向前對齊,所以我添加了:

If j >2 Then 
    sf.Alignment = StringAlignment.Far 
Else 
    sf.Alignment = StringAlignment.Near

e.Graphics.DrawString(Stock.gdColours(j, i).Value, f, Brushes.Black, x, y + 4, sf)

但是結果是對齊是正確的,但是第3列以后的列都從第2列起出現了。

幫助將不勝感激。

對我有用的答案如下。 我使用X1,X2和X3作為接近對齊的字符串的列位置。 當我將中間列更改為高度對齊時,我將中間列的X位置設置為第三列的左側。

         For intRow As Integer = 0 To _aryTopTable.GetLength(0) - 1
            'Draw each row element
            format.Alignment = StringAlignment.Near
            e.Graphics.DrawString(_aryTopTable(intRow, 0), _tableFont, Brushes.Black, X1, Y, format)
            format.Alignment = StringAlignment.Far
            e.Graphics.DrawString(_aryTopTable(intRow, 1), _tableFont, Brushes.Black, X3 - 10, Y, format)
            format.Alignment = StringAlignment.Near
            e.Graphics.DrawString(_aryTopTable(intRow, 2), _tableFont, Brushes.Black, X3, Y, format)
            'Advance Y
            Y = Y + _tableFont.Height + Yp
        Next

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM