本文整理汇总了C#中System.Drawing.Printing.PrintPageEventArgs.HasMorePages属性的典型用法代码示例。如果您正苦于以下问题:C# PrintPageEventArgs.HasMorePages属性的具体用法?C# PrintPageEventArgs.HasMorePages怎么用?C# PrintPageEventArgs.HasMorePages使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Drawing.Printing.PrintPageEventArgs
的用法示例。
在下文中一共展示了PrintPageEventArgs.HasMorePages属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: printButton_Click
// Specifies what happens when the user clicks the Button.
private void printButton_Click(object sender, EventArgs e)
{
try
{
// Assumes the default printer.
pd.Print();
}
catch(Exception ex)
{
MessageBox.Show("An error occurred while printing", ex.ToString());
}
}
// Specifies what happens when the PrintPage event is raised.
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
// Draw a picture.
ev.Graphics.DrawImage(Image.FromFile("C:\\My Folder\\MyFile.bmp"), ev.Graphics.VisibleClipBounds);
// Indicate that this is the last page to print.
ev.HasMorePages = false;
}
示例2: Form1
//引入命名空间
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form {
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.ComponentModel.Container components = null;
private System.Windows.Forms.PrintDialog printDialog1;
private System.Drawing.Printing.PrintDocument ThePrintDocument = null;
private System.IO.StringReader myStringReader = null;
public Form1() {
ThePrintDocument = new System.Drawing.Printing.PrintDocument();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.printDialog1 = new System.Windows.Forms.PrintDialog();
this.SuspendLayout();
this.richTextBox1.Location = new System.Drawing.Point(72, 16);
this.richTextBox1.Size = new System.Drawing.Size(344, 320);
this.richTextBox1.Text = "richTextBox1";
this.button1.Location = new System.Drawing.Point(128, 352);
this.button1.Text = "&Print";
this.button1.Click += new System.EventHandler(this.button1_Click);
this.button2.Location = new System.Drawing.Point(280, 352);
this.button2.Text = "&Close";
this.button2.Click += new System.EventHandler(this.button2_Click);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(488, 381);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button2,
this.button1,
this.richTextBox1});
this.ResumeLayout(false);
}
[STAThread]
static void Main() {
Application.Run(new Form1());
}
private void button2_Click(object sender, System.EventArgs e) {
Close();
}
private void button1_Click(object sender, System.EventArgs e) {
ThePrintDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(PrintPage);
printDialog1.Document = ThePrintDocument;
string strText = this.richTextBox1.Text;
myStringReader = new System.IO.StringReader(strText);
if (printDialog1.ShowDialog() == DialogResult.OK) {
this.ThePrintDocument.Print();
}
}
protected void PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs ev) {
float linesPerPage = 0;
float yPosition = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null;
Font printFont = this.richTextBox1.Font;
SolidBrush myBrush = new SolidBrush(Color.Black);
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);
while (count < linesPerPage && ((line = myStringReader.ReadLine()) != null)) {
yPosition = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, myBrush, leftMargin,yPosition, new StringFormat());
count++;
}
if (line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
myBrush.Dispose();
}
}