Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
vb.net打印datagridview列对齐_Vb.net_Printing_Datagridview_Alignment - Fatal编程技术网

vb.net打印datagridview列对齐

vb.net打印datagridview列对齐,vb.net,printing,datagridview,alignment,Vb.net,Printing,Datagridview,Alignment,“我的网格”显示时,前3列左对齐,后4列右对齐 使用此代码e.Graphics.DrawString(Stock.gdcolors(j,i).Value,f,画笔.黑色,x,y+4) 所有列左对齐打印。 因为我需要第3列以后的列右对齐,所以我添加了: If j >2 Then sf.Alignment = StringAlignment.Far Else sf.Alignment = StringAlignment.Near e.Graphics.DrawStrin

“我的网格”显示时,前3列左对齐,后4列右对齐

使用此代码
e.Graphics.DrawString(Stock.gdcolors(j,i).Value,f,画笔.黑色,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

我已经格式化了你的代码,对吗?似乎缺少一个
EnfIF
。@DontVoteMeDown检查您的评论,如果没有,请结束enfif@SATSON很抱歉,我已经好几年没碰vb了。无论如何,你知道…在e.graphics之前有一个“如果结束”——我只是错过了复制它。代码不需要这么多的“标签”。