datagridview打印问题 [英] datagridview printing problem

查看:62
本文介绍了datagridview打印问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先让我说我只是在学习VB,对此我一无所知,但是我愿意尽一切努力来学习VB并使用任何人的建议.

Let me start by saying that I am just learning VB and I know nothing about it, but I am willing to put in all of the effort in my power to learn it and use anyone's suggestions.

我正在尝试打印出一个datagridview,但我不需要它采用网格格式,只是字段之间的空格有点像这样:

I am trying to print out a datagridview and I dont need it to be in the grid format, just spaces between the fields kind of like this:

数据1数据2数据3数据3数据4

data 1                   data 2                    data 3                      data 4

数据5数据6数据7数据7数据8

data 5                   data 6                    data 7                      data 8

我放了一些代码,从每个单元格获取数据并将其打印出来,但是我遇到的问题是,它们全部覆盖彼此.我能描述的唯一方法是,如果纸张卡在打印机中,并且只是一遍又一遍地保持在同一位置进行打印.

I have put some code together that takes the data from each cell and prints it out but the problem I am having is that it is all writing over the top of each other. The only way that I can describe it would be if the paper got stuck in the printer and it just kept printing in the same spot over and over.

这是我的代码,希望有人可以帮助我获得数据之间我需要的所有空间.

Here is the code that I have, hopefully someone can help me out to get all of the spaces I need between the data.

非常感谢您的光临

约翰

私有 Sub document_PrintPage( ByVal 发件人 对象 ,_

 Private Sub document_PrintPage(ByVal sender As Object, _

ByVal e As System.Drawing.Printing.PrintPageEventArgs)_

ByVal e As System.Drawing.Printing.PrintPageEventArgs) _

句柄 docToPrint.PrintPage

Handles docToPrint.PrintPage

暗淡 线 字符串

Dim line As String

对于 每个 DataGridViewRow DataGridView1.Rows

For Each row As DataGridViewRow In DataGridView1.Rows

line = 字符串 .空

line = String.Empty

对于 每个 单元格 DataGridViewCell 行中.单元格

For Each cell As DataGridViewCell In row.Cells

line + = cell.Value.ToString()& vbTab

line += cell.Value.ToString() & vbTab

下一个

Next

'在此处将行渲染到打印机

' Render line to printer here

暗淡 printFont As 新建 System.Drawing.Font _

Dim printFont As New System.Drawing.Font _

( "Arial" ,15,System.Drawing.FontStyle.Regular)

("Arial", 15, System.Drawing.FontStyle.Regular)

e.Graphics.DrawString(line,printFont,System.Drawing.Brushes.Black,10,10)

e.Graphics.DrawString(line, printFont, System.Drawing.Brushes.Black, 10, 10)

下一个

Next

结束

 

推荐答案

jnelsonjr,

jnelsonjr,

我希望您现在已经解决了您的问题.我也是一个学习者,但我相信您的问题出在以下陈述中:

I hope that you have solved your problem by now.  I'm a learner too, but I believe that your problem is in this statement:

e.Graphics.DrawString(line,printFont,System.Drawing.Brushes.Black,10,10)

e.Graphics.DrawString(line, printFont, System.Drawing.Brushes.Black, 10, 10)

DrawString方法将所有字符串变量(线)绘制到左侧边距的右侧10个像素处,并从顶部边距向下方绘制10个像素.尝试这样的事情:

The DrawString method draws all your string variables (line) 10 pixels to the right of the left margin and 10 pixels down from the top margin.  Try something like this:

Y + = 20
e.Graphics.DrawString(line,printFont,System.Drawing.Brushes.Black,10,Y)

Y += 20
e.Graphics.DrawString(line, printFont, System.Drawing.Brushes.Black, 10, Y)

然后,每行将在前一行下方.我没有使用vbTab,所以我不知道一行中的单元格值是否按照您的需要进行分隔.如果不是,则可以考虑使用DrawString绘制每个值并通过增加X和Y参数来隔开它们.

Each line will then be below the previous line.  I have not used vbTab so I don't know if the cell values in a row are being seperated as you desire.  If they aren't you might consider using DrawString to draw each value and space them by incrementing both the X, and Y parameters.

e.Graphics.DrawString(line,printFont,System.Drawing.Brushes.Black,X,Y)

e.Graphics.DrawString(line, printFont, System.Drawing.Brushes.Black, X, Y)

好运.


这篇关于datagridview打印问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆