vb.net 教程 11-1 打印组件 2 PrintDialog 2

前端之家收集整理的这篇文章主要介绍了vb.net 教程 11-1 打印组件 2 PrintDialog 2前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
上一节介绍了PrintDialog的一些基础,这节继续介绍。
先说一下DefaultPageSettings,这个是默认的页面设置
其实个人感觉PrintDialog.DefaultPageSettings属性和PageSetupDialog.PageSettings属性有些重复。
虽然PrintDialog.DefaultPageSettings在msdn中显示是ReadOnly,但是还是可以设置的。

使用上一节的窗体,将按钮代码修改为以下内容
    Private Sub Button2_Click(sender As Object,e As EventArgs) Handles Button2.Click
        Dim ps As Printing.PrinterSettings
        If PrintDialog1.ShowDialog = DialogResult.OK Then
            ps = PrintDialog1.PrinterSettings
        Else
            Exit Sub
        End If

        TextBox1.Text = "彩色打印:" & ps.DefaultPageSettings.Color & ControlChars.CrLf &
            "打印方向:" & IIf(ps.DefaultPageSettings.Landscape,"横向","竖向") & ControlChars.CrLf &
            "打印边距:" & ps.DefaultPageSettings.Margins.Top & "*" & ps.DefaultPageSettings.Margins.Bottom &
            "*" & ps.DefaultPageSettings.Margins.Left & "*" & ps.DefaultPageSettings.Margins.Right & ControlChars.CrLf &
            "打印机名称:" & ps.DefaultPageSettings.PrinterSettings.PrinterName

        ps.DefaultPageSettings.Color = False
        ps.DefaultPageSettings.Landscape = True
        ps.DefaultPageSettings.Margins = New Printing.Margins(10,10,10)
        ps.DefaultPageSettings.PrinterSettings.PrinterName = “Microsoft XPS Document Writer”

        TextBox1.Text = TextBox1.Text & ControlChars.CrLf & "---------------" & ControlChars.CrLf &
            "彩色打印:" & ps.DefaultPageSettings.Color & ControlChars.CrLf &
            "打印方向:" & IIf(ps.DefaultPageSettings.Landscape,"竖向") & ControlChars.CrLf &
            "打印边距:" & ps.DefaultPageSettings.Margins.Top & "*" & ps.DefaultPageSettings.Margins.Bottom &
            "*" & ps.DefaultPageSettings.Margins.Left & "*" & ps.DefaultPageSettings.Margins.Right & ControlChars.CrLf &
            "打印机名称:" & ps.PrinterName

    End Sub
运行效果如下:

最后一段代码,我特地用了 "打印机名称:" & ps.PrinterName,
Printing.PrinterSettings.DefaultPageSettings是一个Printing.PageSetting类。
Printing.PageSetting包含PrinterSettings属性,是一个Printing.PrinterSettings类。
这两个类相互包含无穷尽。
Printing.PrinterSettings.DefaultPageSettings.PrinterSettings.DefaultPageSettings……


另外顺带说一下,PrinterSettings有个比较重要的属性:InstalledPrinters,可以枚举当前安装的打印机,代码如下:

    Private Sub Button3_Click(sender As Object,e As EventArgs) Handles Button3.Click
        TextBox1.Text = ""
        For Each printerName As String In Printing.PrinterSettings.InstalledPrinters
            TextBox1.Text &= printerName & ControlChars.CrLf
        Next

    End Sub

运行效果如图:


学习更多vb.net知识,请参看 vb.net 教程 目录
原文链接:https://www.f2er.com/vb/256586.html

猜你在找的VB相关文章