本文整理汇总了C#中System.Windows.Forms.PrintDialog.Document属性的典型用法代码示例。如果您正苦于以下问题:C# PrintDialog.Document属性的具体用法?C# PrintDialog.Document怎么用?C# PrintDialog.Document使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.PrintDialog
的用法示例。
在下文中一共展示了PrintDialog.Document属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Button1_Click
// Declare the PrintDocument object.
private System.Drawing.Printing.PrintDocument docToPrint =
new System.Drawing.Printing.PrintDocument();
// This method will set properties on the PrintDialog object and
// then display the dialog.
private void Button1_Click(System.Object sender,
System.EventArgs e)
{
// Allow the user to choose the page range he or she would
// like to print.
PrintDialog1.AllowSomePages = true;
// Show the help button.
PrintDialog1.ShowHelp = true;
// Set the Document property to the PrintDocument for
// which the PrintPage Event has been handled. To display the
// dialog, either this property or the PrinterSettings property
// must be set
PrintDialog1.Document = docToPrint;
DialogResult result = PrintDialog1.ShowDialog();
// If the result is OK then print the document.
if (result==DialogResult.OK)
{
docToPrint.Print();
}
}
// The PrintDialog will print the document
// by handling the document's PrintPage event.
private void document_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
// Insert code to render the page here.
// This code will be called when the control is drawn.
// The following code will render a simple
// message on the printed document.
string text = "In document_PrintPage method.";
System.Drawing.Font printFont = new System.Drawing.Font
("Arial", 35, System.Drawing.FontStyle.Regular);
// Draw the content.
e.Graphics.DrawString(text, printFont,
System.Drawing.Brushes.Black, 10, 10);
}
示例2: PrintDialogPrint
//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Printing;
public class PrintDialogPrint : Form
{
public PrintDialogPrint()
{
this.cmdPrint = new System.Windows.Forms.Button();
this.SuspendLayout();
//
this.cmdPrint.Location = new System.Drawing.Point(109, 122);
this.cmdPrint.Size = new System.Drawing.Size(75, 23);
this.cmdPrint.Text = "Print";
this.cmdPrint.UseVisualStyleBackColor = true;
this.cmdPrint.Click += new System.EventHandler(this.cmdPrint_Click);
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(272, 260);
this.Controls.Add(this.cmdPrint);
this.Text = "Simple Print";
this.ResumeLayout(false);
}
private void cmdPrint_Click(object sender, EventArgs e)
{
PrintDocument doc = new PrintDocument();
doc.PrintPage += this.Doc_PrintPage;
PrintDialog dlgSettings = new PrintDialog();
dlgSettings.Document = doc;
if (dlgSettings.ShowDialog() == DialogResult.OK)
{
doc.Print();
}
}
private void Doc_PrintPage(object sender, PrintPageEventArgs e)
{
Font font = new Font("Arial", 30);
float x = e.MarginBounds.Left;
float y = e.MarginBounds.Top;
float lineHeight = font.GetHeight(e.Graphics);
for (int i = 0; i < 5; i++)
{
e.Graphics.DrawString("This is line " + i.ToString(),font, Brushes.Black, x, y);
y += lineHeight;
}
y += lineHeight;
e.Graphics.DrawImage(Image.FromFile("c:\\YourFile.bmp"), x, y);
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new PrintDialogPrint());
}
private System.Windows.Forms.Button cmdPrint;
}