用左printdocument 同 printpreivewdialog咁點可以多頁打印..
現在只能打印當前頁...
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int temp=1;//設置系數格行距離
e.Graphics.DrawString("大東物業", new Font("宋體", 30), Brushes.Black, 100, 80);//設置標題
e.Graphics.DrawString("樓宇/大廈", new Font("宋體", 15), Brushes.Black, 100, 145);//設置標題
e.Graphics.DrawString("座數", new Font("宋體", 15), Brushes.Black, 250, 145);
e.Graphics.DrawString("樓層", new Font("宋體", 15), Brushes.Black, 350, 145);
e.Graphics.DrawString("單位", new Font("宋體", 15), Brushes.Black, 450, 145);
e.Graphics.DrawString("售價", new Font("宋體", 15), Brushes.Black, 550, 145);
e.Graphics.DrawString("租金", new Font("宋體", 15), Brushes.Black, 650, 145);
for (int i = 0; i < dataGridView1.RowCount ; i++)
{
if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true)
{
e.Graphics.DrawString(dataGridView1.Rows[i].Cells["garden"].Value.ToString(), new Font("宋體", 15), Brushes.Black, 100, 160+temp*30);
e.Graphics.DrawString(dataGridView1.Rows[i].Cells["block"].Value.ToString(), new Font("宋體", 15), Brushes.Black, 250, 160 + temp * 30);
e.Graphics.DrawString(dataGridView1.Rows[i].Cells["floor"].Value.ToString(), new Font("宋體", 15), Brushes.Black, 350, 160 + temp * 30);
e.Graphics.DrawString(dataGridView1.Rows[i].Cells["unit"].Value.ToString(), new Font("宋體", 15), Brushes.Black, 450, 160 + temp * 30);
e.Graphics.DrawString(dataGridView1.Rows[i].Cells["sellprice"].Value.ToString(), new Font("宋體", 15), Brushes.Black, 550, 160 + temp * 30);
e.Graphics.DrawString(dataGridView1.Rows[i].Cells["rentprice"].Value.ToString(), new Font("宋體", 15), Brushes.Black, 650, 160 + temp * 30);
temp++;
}
}
}
private void button6_Click(object sender, EventArgs e)
{
//開啟操作係統的防鋸齒功能
this.printPreviewDialog1.UseAntiAlias = true;
//設置預覽的文檔
this.printPreviewDialog1.Document = this.printDocument1;
//打開預覽的窗口
printPreviewDialog1.ShowDialog();
}