如何在VB.net中打印? [英] How do I print in VB.net?

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

问题描述

转载为问题格式。我是VB.net的新手,需要一个简单的工作示例,说明如何打印列表框的内容。我在网上找到的所有例子都是错误的或者是过度的。熟悉VB.net的人可以发布代码,告诉我如何设置打印吗?

解决方案

参考



如何操作-you-print-the-list-of-a-list-box [ ^ ]


 < span class =code-keyword>私有  Sub  Button1_Click( ByVal  sender 作为系统。对象 ByVal  e  As  System.EventArgs)句柄 Button1.Click 
PrintDocument1.Print()
结束 Sub

私有 Sub PrintDocument1_PrintPage( ByVal 发​​件人作为系统。对象 ByVal e As System.Drawing.Printing.PrintPageEventArgs)句柄 PrintDocument1.PrintPage
Dim fnt 作为 字体( Arial 10 ,FontStyle。 Regular,GraphicsUnit.Point)
Dim ListBoxItem As 字符串 = 字符串 .Empty
对于 每个 LBItem 作为 字符串 ListBox1.Items
ListBoxItem = ListBoxItem& vbCrLf& LBItem
Next
ListBoxItem = ListBoxItem.Substring(vbCrLf.Length)
e.Graphics.DrawString(ListBoxItem,fnt,Brushes。黑色, 0 0
e.HasMorePages = 错误
结束 Sub


Reposted in question format.I'm new to VB.net and need a simple working example of how to print the contents of a listbox. All of the examples that I've found on the web are either buggy or are overkill. Could someone familiar with VB.net please post code that will show me how to set up the print?

解决方案

Refer

How-do-you-print-the-contents-of-a-list-box[^]


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 fnt As New Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Point)
        Dim ListBoxItem As String = String.Empty
        For Each LBItem As String In ListBox1.Items
            ListBoxItem = ListBoxItem & vbCrLf & LBItem
        Next
        ListBoxItem = ListBoxItem.Substring(vbCrLf.Length)
        e.Graphics.DrawString(ListBoxItem, fnt, Brushes.Black, 0, 0)
        e.HasMorePages = False
End Sub


这篇关于如何在VB.net中打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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