標籤:int() tom review 預覽列印 nts this ogr point pointf
引入printDocument控制項
/// <summary>
/// 列印方法
/// </summary>
public void Print()
{
//執行個體化列印對象
PrintDocument printDocument1 = new PrintDocument();
//設定列印用的紙張,當設定為Custom的時候,可以自訂紙張的大小
printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Custum", 420, (PrintData.Count * 155) + (PrintData.Count * 10) + 10);
//註冊PrintPage事件,列印每一頁時會觸發該事件
printDocument1.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage);
//初始化預覽列印對話方塊對象
PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
//將printDocument1對象賦值給預覽列印對話方塊的Document屬性
printPreviewDialog1.Document = printDocument1;
//開啟預覽列印對話方塊
DialogResult result = printPreviewDialog1.ShowDialog();
if (result == DialogResult.OK)
{
printDocument1.Print();//開始列印--printDocument控制項的PrintPage事件
}
}
//printDocument控制項的PrintPage事件
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//畫出列印內容
e.Graphics.DrawString("吳世傑", new System.Drawing.Font("宋體", 6, FontStyle.Bold), new SolidBrush(Color.Black), new PointF(5, 53));
}
C#winfrom列印與預覽列印