在VB6中,若是要自定義紙張很方便:
Rpt.PaperSize = crPaperUser
Rpt.SetUserPaperSize lZZG, lZZKhtml
但在C#中卻不行了,沒有發現 SetUserPaperSize。如今同事的問題是預覽時很正常顯示中一刀,但點擊自帶的工具欄打印時,就是 Letter 紙。網絡
本想用 Reflector 跟蹤出是否有哪一個地方能夠利用的,沒有結果。
再找網絡上的說法,終於在
http://www.cnblogs.com/zeroone/p/3306172.html
中看到關鍵一行
rptDoc.PrintToPrinter(1, true, 0, 0);工具
它有一行:PrinterSettings printerSettings = document.PrinterSettings;
而系統自帶的工具欄打印時,則是
PrinterSettings settings = new PrinterSettings();this
CrystalDecisions.Windows.Forms.CrystalReportViewer
public virtual void PrintReport()
{
this.pageView.PrintReport();
}spa
CrystalDecisions.Windows.Forms.PageView
public virtual void PrintReport()
{
ReportDocumentBase activeDocument = this.GetActiveDocument();
if (activeDocument != null)
{
activeDocument.Print();
}
}orm
CrystalDecisions.Windows.Forms.ReportDocumentBase
public void Print()
{
}
想代替,但裏面的代碼引用了較多私有方法(如:GetLastPageNumber)htm
若是能重寫 PrinterSettings 將是無比興奮。
可是,沒有成功blog
namespace CrystalDecisions.Windows.Forms
{
class PrinterSettings : System.Drawing.Printing.PrinterSettings
{
public PrinterSettings()
: base()
{
// 它是隻讀的,另外一個對應變量又是私有的
this.DefaultPageSettings = new PageSettings(this);
}
}ci
class PageSettings:System.Drawing.Printing.PageSettings
{
public PageSettings(System.Drawing.Printing.PrinterSettings printerSettings):base(printerSettings)
{
base.PaperSize = new System.Drawing.Printing.PaperSize("Temp", 100, 100);
}
}
}get