敬阿奇,C#程序设计教程(第3版),第5章要素.ppt

敬阿奇,C#程序设计教程(第3版),第5章要素

5.7.2 选择打印机打印文件 【例5.14】使用 PrintDialog 组件选择要使用的打印机。 有两个要处理的事件。在第一个事件(Button 控件的 Click 事件)中,实例化 PrintDialog 类,并在 DialogResult 属性中捕获用户选择的打印机。在第二个事件(PrintDocument 组件的 PrintPage 事件)中,将一个示例文档打印到指定的打印机。 private void button1_Click(object sender, System.EventArgs e) { PrintDialog printDialog1 = new PrintDialog(); printDialog1.Document = printDocument1; DialogResult result = printDialog1.ShowDialog(); if (result == DialogResult.OK) { printDocument1.Print(); } } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.FillRectangle(Brushes.Red

文档评论(0)

1亿VIP精品文档

相关文档