版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
上一节介绍了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, 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教程目录
版权声明:本文为CSDN博主「VB.Net」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。