[Serializable()] public class OwnerPrintDocument : System.Drawing.Printing.PrintDocument //PrintDocumentクラスを継承します
{
//印刷する2つのSPREAD
private FarPoint.Win.Spread.FpSpread op_Spread1;
private FarPoint.Win.Spread.FpSpread op_Spread2;
//各タイトル
public string Title1;
public string Title2;
public OwnerPrintDocument(FarPoint.Win.Spread.FpSpread Spread_1, FarPoint.Win.Spread.FpSpread Spread_2) : base()
{
op_Spread1 = Spread_1;
op_Spread2 = Spread_2;
}
protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs ev)
{
//OnBeginPrintメソッドをオーバーライドします
base.OnBeginPrint(ev);
}
protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
{
//OnPrintPage メソッドをオーバーライドします
base.OnPrintPage(e);
//********************
// FpSpread1の出力
//********************
//描画位置を設定します
Rectangle rect1 = new Rectangle(e.PageBounds.X + 30, e.PageBounds.Y + 40, e.PageBounds.Width / 2, e.PageBounds.Height / 2);
//必要なページ数を取得します
int cnt1 = op_Spread1.GetOwnerPrintPageCount(e.Graphics, rect1, 0);
//印刷するページが存在する場合のみ出力します
if (cnt1 > 0)
{
op_Spread1.OwnerPrintDraw(e.Graphics, rect1, 0, cnt1);
e.HasMorePages = false;
}
//**************************************
// FpSpread1上部にタイトルを描画します
//**************************************
RectangleF drect1 = new RectangleF();
drect1.X = e.PageBounds.X + 30;
drect1.Y = e.PageBounds.Y + 10;
drect1.Width = e.PageBounds.Width / 2;
drect1.Height = e.PageBounds.Height / 2;
Brush b1 =new SolidBrush(Color.Red);
e.Graphics.DrawString(Title1, new Font("MS Pゴシック", 14, FontStyle.Bold | FontStyle.Italic), b1, drect1);
b1.Dispose();
//********************
// FpSpread2の出力
//********************
//描画位置を設定します
Rectangle rect2 = new Rectangle(e.PageBounds.X + 30, e.PageBounds.Y + 210, e.PageBounds.Width - 100, e.PageBounds.Height / 2);
//必要なページ数を取得します
int cnt2 = op_Spread2.GetOwnerPrintPageCount(e.Graphics, rect2, 0);
//印刷するページが存在する場合のみ出力します
if (cnt2 > 0)
{
op_Spread2.OwnerPrintDraw(e.Graphics, rect2, 0, cnt2);
e.HasMorePages = false;
}
//**************************************
// FpSpread2上部にタイトルを描画します
//**************************************
RectangleF drect2 = new RectangleF();
drect2.X = e.PageBounds.X + 180;
drect2.Y = e.PageBounds.Y + 180;
drect2.Width = e.PageBounds.Width / 2;
drect2.Height = e.PageBounds.Height / 2;
Brush b2 =new SolidBrush(Color.Blue);
e.Graphics.DrawString(Title2, new Font("Times New Roman", 18, FontStyle.Underline), b2, drect2);
b2.Dispose();
}
}
<Serializable()> Public Class OwnerPrintDocument
'PrintDocumentクラスを継承します
Inherits System.Drawing.Printing.PrintDocument
'印刷する2つのSPREAD
Private op_Spread1 As FarPoint.Win.Spread.FpSpread
Private op_Spread2 As FarPoint.Win.Spread.FpSpread
'各タイトル
Public Title1 As String
Public Title2 As String
Public Sub New(ByVal Spread_1 As FarPoint.Win.Spread.FpSpread, ByVal Spread_2 As FarPoint.Win.Spread.FpSpread)
op_Spread1 = Spread_1
op_Spread2 = Spread_2
End Sub
Protected Overrides Sub OnBeginPrint(ByVal e As System.Drawing.Printing.PrintEventArgs)
'OnBeginPrintメソッドをオーバーライドします
MyBase.OnBeginPrint(e)
End Sub
Protected Overrides Sub OnPrintPage(ByVal e As System.Drawing.Printing.PrintPageEventArgs)
'OnPrintPageメソッドをオーバーライドします
MyBase.OnPrintPage(e)
'********************
' FpSpread1の出力
'********************
'描画位置を設定します
Dim rect1 As New Rectangle(e.PageBounds.X + 30, e.PageBounds.Y + 40, e.PageBounds.Width / 2, e.PageBounds.Height / 2)
'必要なページ数を取得します
Dim cnt1 As Integer = op_Spread1.GetOwnerPrintPageCount(e.Graphics, rect1, 0)
'印刷するページが存在する場合のみ出力します
If cnt1 > 0 Then
op_Spread1.OwnerPrintDraw(e.Graphics, rect1, 0, cnt1)
e.HasMorePages = False
End If
'**************************************
' FpSpread1上部にタイトルを描画します
'**************************************
Dim drect1 As New RectangleF
drect1.X = e.PageBounds.X + 30
drect1.Y = e.PageBounds.Y + 10
drect1.Width = e.PageBounds.Width / 2
drect1.Height = e.PageBounds.Height / 2
Dim b1 As Brush = New SolidBrush(Color.Red)
e.Graphics.DrawString(Title1, New Font("MS Pゴシック", 14, FontStyle.Bold Or FontStyle.Italic), b1, drect1)
b1.Dispose()
'********************
' FpSpread2の出力
'********************
'描画位置を設定します
Dim rect2 As New Rectangle(e.PageBounds.X + 30, e.PageBounds.Y + 210, e.PageBounds.Width - 100, e.PageBounds.Height / 2)
'必要なページ数を取得します
Dim cnt2 As Integer = op_Spread2.GetOwnerPrintPageCount(e.Graphics, rect2, 0)
'印刷するページが存在する場合のみ出力します
If cnt2 > 0 Then
op_Spread2.OwnerPrintDraw(e.Graphics, rect2, 0, cnt2)
e.HasMorePages = False
End If
'**************************************
' FpSpread2上部にタイトルを描画します
'**************************************
Dim drect2 As New RectangleF
drect2.X = e.PageBounds.X + 180
drect2.Y = e.PageBounds.Y + 180
drect2.Width = e.PageBounds.Width / 2
drect2.Height = e.PageBounds.Height / 2
Dim b2 As Brush = New SolidBrush(Color.Blue)
e.Graphics.DrawString(Title2, New Font("Times New Roman", 18, FontStyle.Underline), b2, drect2)
b2.Dispose()
End Sub
End Class