快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

vb.net窗口打印控件 vb打印功能

vb.net如何实现打印DataGridView1里的内容,求源码

使用 PrintDocument 控件的 Print() 方法可以打印指定对象中的内容,参考代码如下:

创新互联网络公司拥有十载的成都网站开发建设经验,上千余家客户的共同信赖。提供成都网站设计、成都网站制作、网站开发、网站定制、外链、建网站、网站搭建、响应式网站建设、网页设计师打造企业风格,提供周到的售前咨询和贴心的售后服务

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

PrintDocument1.Print()

End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

Dim bm As New Bitmap(Me.DataGridView1.Width, Me.DataGridView1.Height)

DataGridView1.DrawToBitmap(bm, New Rectangle(0, 0, Me.DataGridView1.Width, Me.DataGridView1.Height))

e.Graphics.DrawImage(bm, 0, 0)

End Sub

VS2005如何用VB.NET代码实现打印功能

有个PrintDocument控件,可以实现打印。。。

MSDN原话:

使用 PrintDocument 组件

涉及 PrintDocument 组件的两种主要情况是:

简单的打印作业,如打印单个文本文件。在这种情况下,应将 PrintDocument 组件添加到 Windows 窗体,然后在 PrintPage 事件处理程序中添加打印文件的编程逻辑。 该编程逻辑应以使用 Print 方法打印文档结束。

此方法向打印机发送一个 Graphics 对象,该对象包含在 PrintPageEventArgs 类的 Graphics 属性中。

有关如何使用 PrintDocument 组件打印文本文档的示例,请参见

如何:打印 Windows 窗体中的多页文本文件。

更为复杂的打印作业,如想要重新使用已编写的打印逻辑的情况。

在这种情况下,应从 PrintDocument 组件派生一个新组件,并重写

(请参见 Visual Basic 的 重写或 C# 的 重写) PrintPage 事件。

将 PrintDocument 组件添加到窗体后,它出现在 Windows 窗体设计器底部的栏中

关于vb.net添加打印控件的用法

txt文件:

procedure TForm1.Button1Click(Sender: TObject);

var

MyFile: TextFile;

SourceFile:TextFile;

Tmp:String;

begin

AssignPrn(MyFile);

AssignFile(SourceFile,'FilePath');

Reset(SourceFile);

Rewrite(MyFile);

Readln(SourceFile,Tmp);

While Not EOF(SourceFile) do

Begin

Writeln(MyFile, Tmp);

Readln(SourceFile,Tmp);

System.CloseFile(MyFile);

end;

图形文件需要TPrinter.canvas来打印了,

在vb.net 里面,如何打印当前窗口

有截屏键Ctrl + Alt + prtScr/sysRq(prtScr/sysRq在F12旁边),再打开画图、WORD等粘贴就行了

VB.NET打印问题(有滚动条控件的内容怎么全部打印)

参考:

把执行SQL语句后得到的记录集逐条(含字段名)显示在LISTVIEW控件中

'----------------------------------------------------------------

Public Sub ListUpdate(ByRef rs As Recordset, ByRef lv As ListView)

Dim head As ColumnHeader, Item As ListItem

Dim i As Integer, j As Integer

Dim lvWidth As Integer

lvWidth = lv.Width

'初始化LISTVIEW的某些属性

lv.View = lvwReport

lv.GridLines = True

lv.FullRowSelect = True

lv.ListItems.Clear

lv.ColumnHeaders.Clear

For i = 0 To rs.Fields.Count - 1

Set head = lv.ColumnHeaders.Add

head.Text = rs.Fields(i).Name

head.Width = lvWidth / rs.Fields.Count

Next

For j = 1 To PERPAGE

If rs.EOF Then Exit For

Set Item = lv.ListItems.Add

Item.Text = "" rs.Fields(0).Value

For i = 1 To rs.Fields.Count - 1

Item.SubItems(i) = "" rs.Fields(i).Value

Next

rs.MoveNext

Next

End Sub

' 打印

Public Sub PrintRecordset(ByRef recRecordset As Recordset, ByVal strType As String)

Dim LeftMargin As Integer

Dim HeadTopPosition As Integer

Dim FieldNum As Integer

Dim PageCounter As Integer

Dim MyRecordset As ADODB.Recordset

Const FooterTopPosition = 24

Set MyRecordset = recRecordset

PageCounter = 1

' 设 置Printer 对 象 坐 标 的 度 量 单 位 为 厘 米

Printer.ScaleMode = vbCentimeters

LeftMargin = 1.5

HeadTopPosition = 2

' 定 义 打 印 页 左 上 角 的X 坐 标 和Y 坐 标, 通 过 改 变ScaleLeft 和ScaleTop 的 值, 可 改 变 打 印 页 的 左 边 距 和 上 边 距

Printer.ScaleLeft = -LeftMargin

Printer.ScaleTop = -HeadTopPosition

Printer.Font.Name = "Times New Roman"

Printer.Font.Size = 12

Printer.Print "音像店顾客管理系统"

Printer.Print strType

Printer.Print ""

If MyRecordset.EOF And MyRecordset.BOF Then

MsgBox "No Record At Presend!", vbCritical And vbOKOnly, "Print Error"

Exit Sub

End If

MyRecordset.MoveFirst

Do Until Printer.CurrentY FooterTopPosition

'Print the fields of the recordset in sequence

For FieldNum = 0 To MyRecordset.Fields.Count - 1

Printer.Print MyRecordset.Fields(FieldNum).Name _

": " _

MyRecordset.Fields(FieldNum).Value

If Printer.CurrentY FooterTopPosition Then

Printer.CurrentX = 8

Printer.Print "Page: " PageCounter

' 创 建 多 页 文 档

Printer.NewPage

PageCounter = PageCounter + 1

End If

Next FieldNum

MyRecordset.MoveNext

If MyRecordset.EOF Then Exit Do

' 在 记 录 之 间 空 一 行

Printer.Print ""

Loop

'Print the Page number as a footer

Printer.CurrentX = 8

Printer.CurrentY = FooterTopPosition

Printer.Print "Page: " PageCounter

' 将 输 出 送 到 打 印 机

Printer.EndDoc

End Sub

vb.net打印问题

PRINTER.PRINT 用这个,直接打印到默认打印机了,位置的确定是你根据控件的位置就可以确定了


新闻标题:vb.net窗口打印控件 vb打印功能
网站网址:http://6mz.cn/article/docojps.html

其他资讯