使用printDocument打印怎么实现有页码范围的打印,也就是只想打印其中几页的内容,如2-5页的内容
不是全部打印
代码如下:
private void btnPrint_Click(object sender, System.EventArgs e)
{
printDialog1.AllowSomePages =true;
if (printDialog1.ShowDialog() == DialogResult.OK){
printDocument1.PrinterSettings = printDialog1.PrinterSettings ;
printDocument1.Print();} }
急急急!!!!
不是全部打印
代码如下:
private void btnPrint_Click(object sender, System.EventArgs e)
{
printDialog1.AllowSomePages =true;
if (printDialog1.ShowDialog() == DialogResult.OK){
printDocument1.PrinterSettings = printDialog1.PrinterSettings ;
printDocument1.Print();} }
急急急!!!!
不好使呀
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
CrDiskFileDestinationOptions.DiskFileName=Fname;
ExportOptions CrExportOptions = myReportDoc.ExportOptions;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile ;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
myReportDoc.Export();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.WriteFile(Fname);
Response.Flush();
Response.Close();
System.IO.File.Delete(Fname);
我想用printDocument和printDialog控制打印的页码范围
不知道怎么实现
this.printDialog1.ShowDialog();
不就显示出来了吗?
不是选择区域打印
1.设置PrintSettings中的MinimumPage(可选择的最小页)、MaximumPage属性,将PrintSettings关联到PrintDialog;
2.设置PrintDialog的AllowSomePages、AllowSelection属性为True,显示PrintDialg让用户设定;
3.在PrintDocument的OnPrintPage事件处理程序中,根据PrintSettings的PrintRange、FromPage、ToPage属性来确定需要打印的页即可。希望我的研究对您有用,祝你工作愉快。
this.printDialog1.AllowSomePages=true;
printDialog1.AllowSelection=true;
是否启用页码范围选择按钮
感谢大家的帮助
建议:
1。查看MSDN中的那几个类;
2。买本合适的书看看。
{
string line = null;
float linesPerPage = ev.MarginBounds.Height / theFont.GetHeight(ev.Graphics);
bool isSomePages = ev.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages;
if (isSomePages)
{
while (currPage < ev.PageSettings.PrinterSettings.FromPage)
{
for (int count = 0; count < linesPerPage; count++)
{
line = srToPrint.ReadLine();
if (line == null) break;
}
if (line == null) return;
currPage++;
}
if (currPage > ev.PageSettings.PrinterSettings.ToPage) return;
}
for (int count = 0; count < linesPerPage; count++)
{
line = srToPrint.ReadLine();
if (line == null) break;
ev.Graphics.DrawString(line, theFont, Brushes.Black, ev.MarginBounds.Left,
ev.MarginBounds.Top + (count * theFont.GetHeight(ev.Graphics)), new StringFormat());
}
currPage++;
if (isSomePages && currPage > ev.PageSettings.PrinterSettings.ToPage) return;
if (line != null) ev.HasMorePages = true;
}