本节开始正式学习这些组件的使用。
PageSetupDialog组件的使用,本节暂时不讲实际打印
设计时窗体如图(请自行添加PrintDialog组件):
直接上代码分析:
Private Sub Button1_Click(sender As Object,e As EventArgs) Handles Button1.Click Dim ps As Printing.PrinterSettings If PrintDialog1.ShowDialog = DialogResult.OK Then ps = PrintDialog1.PrinterSettings Else Exit Sub End If TextBox1.Text = "打印机名称:" & ps.PrinterName & ControlChars.CrLf & "支持双面打印:" & IIf(ps.CanDuplex,"是","否") & ControlChars.CrLf & "打印份数:" & ps.Copies & ControlChars.CrLf & "打印起始页:" & ps.FromPage & ControlChars.CrLf & "打印终止页:" & ps.ToPage & ControlChars.CrLf & "支持彩色打印:" & IIf(ps.SupportsColor,"否") & ControlChars.CrLf End Sub
可以看出来,打印对话框和之前将的对话框差不多,都需要 ShowDialog()
先不管其中的灰色项目,将份数设置为4份,按下“打印”按钮:
再将打印对话框和设计时的属性做个对比:
运行效果: