上一节介绍了PrintDialog的一些基础,这节继续介绍。
先说一下DefaultPageSettings,这个是默认的页面设置
虽然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
运行效果如下:
Printing.PrinterSettings.DefaultPageSettings是一个Printing.PageSetting类。
Printing.PageSetting包含PrinterSettings属性,是一个Printing.PrinterSettings类。
这两个类相互包含无穷尽。
Printing.PrinterSettings.DefaultPageSettings.PrinterSettings.DefaultPageSettings……
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