赤い線が表示される
プレビュー時の赤い線は、指定された用紙の幅を示します。指定された用紙の幅よりも、レポート全体の幅が大きい場合に、プレビュー時に赤い線が表示されます。
この赤い線を消すには、レポートの幅(ActiveReportオブジェクトのPrintWidthプロパティ)と左右のマージン(PageSettingsオブジェクトのMargins.Left,Margins.Rightプロパティ)および、とじしろ(PageSettingsオブジェクトのGutterプロパティ)を足した値が、用紙の幅(PrinterオブジェクトのPaperWidthプロパティまたはPaperHeightプロパティ)を超えないようにする必要があります。
つまり、「PageSettings.Margins.Left + PageSettings.Margins.Right + PageSettings.Gutter + PrintWidth <= Document.Printer.PaperWidth(Document.Printer.PaperHeight)」の関係を守る必要があります。
下記の何れかの方法で指定してください。
以下のサンプルコードでは、レポートの幅(PrintWidthプロパティ)を、用紙の向きやマージンおよびとじしろに合わせて調整しています。
Visual Basic
| Visual Basicコード |
コードのコピー
|
|---|---|
Private Sub SectionReport1_ReportStart(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ReportStart
If Me.PageSettings.Orientation = PageOrientation.Landscape Then
' 用紙が横方向の場合
Me.PrintWidth = Me.Document.Printer.PaperHeight _
- (Me.PageSettings.Margins.Left + Me.PageSettings.Margins.Right + Me.PageSettings.Gutter)
Else
' 用紙が縦方向の場合
Me.PrintWidth = Me.Document.Printer.PaperWidth _
- (Me.PageSettings.Margins.Left + Me.PageSettings.Margins.Right + Me.PageSettings.Gutter)
End If
End Sub
|
|
C#
| C#コード |
コードのコピー
|
|---|---|
private void SectionReport1_ReportStart(object sender, EventArgs e)
{
if (this.PageSettings.Orientation == PageOrientation.Landscape)
{
// 用紙が横方向の場合
this.PrintWidth = this.Document.Printer.PaperHeight
- (this.PageSettings.Margins.Left + this.PageSettings.Margins.Right + this.PageSettings.Gutter);
}
else
{
// 用紙が縦方向の場合
this.PrintWidth = this.Document.Printer.PaperWidth
- (this.PageSettings.Margins.Left + this.PageSettings.Margins.Right + this.PageSettings.Gutter);
}
}
|
|
レポートを生成しながらプレビューする
ViewerのDocumentプロパティにレポートのDocumentインスタンスを設定した上で、Run(True)を実行すると、生成されたページから順次プレビューすることが可能です。
![]() |
メモ: レポートの構成によっては、上記の方法が適用できない場合があります。たとえば、Summary***プロパティを使って、総ページ数やレポート全体の集計値を出力するという設定をしたTextBoxを配置している場合には、全レコードの処理が完了してから各ページの描画処理が行われるため、ページの生成完了に遅延が発生します。このような場合には、生成されたページから順次プレビューすることはできません。 |
Visual Basic
| Visual Basicコード |
コードのコピー
|
|---|---|
Dim rpt As New SectionReport1
Viewer1.Document = rpt.Document
rpt.Run(True)
|
|
C#
| C#コード |
コードのコピー
|
|---|---|
SectionReport1 rpt = new SectionReport1();
this.viewer1.Document = rpt.Document;
rpt.Run(true);
|
|
ただし、生成されたページから順次プレビューする処理を、FormのLoadイベントで実装する場合は注意が必要です。LoadイベントがRunメソッドの完了まで継続し、この間の画面表示が更新されません。このため、Run(True)を実行しても、ビューワに順次レポートが表示されることはありません。
FormのLoadイベントを利用する場合、以下のような方法が考えられます。
Visual Basic
| Visual Basicコード |
コードのコピー
|
|---|---|
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim thread As New System.Threading.Thread( _ New System.Threading.ThreadStart(AddressOf Thread1)) thread.IsBackground = True thread.SetApartmentState(Threading.ApartmentState.STA) thread.Start() End Sub Delegate Sub CreateReportDelegate() Private Sub CreateReport() Dim rpt As New SectionReport1 Viewer1.Document = rpt.Document rpt.Run(True) End Sub Private Sub Thread1() Me.Viewer1.Invoke(New CreateReportDelegate(AddressOf CreateReport)) End Sub |
|
C#
| C#コード |
コードのコピー
|
|---|---|
private void Form1_Load(object sender, System.EventArgs e)
{
System.Threading.Thread thread =
new System.Threading.Thread(new System.Threading.ThreadStart(Thread1));
thread.IsBackground = true;
thread.SetApartmentState(System.Threading.ApartmentState.STA);
thread.Start();
}
delegate void CreateReportDelegate();
private void CreateReport()
{
SectionReport1 rpt = new SectionReport1();
this.viewer1.Document = rpt.Document;
rpt.Run(true);
}
void Thread1()
{
this.viewer1.Invoke(new CreateReportDelegate(CreateReport));
}
|
|
Visual Basic
| Visual Basicコード |
コードのコピー
|
|---|---|
Private timer As New Timer()
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
' タイマ・メソッドの作成します。
AddHandler timer.Tick, New EventHandler(AddressOf CreateReport)
timer.Interval = 100
' Loadイベントが終了してから0.1秒後にレポートを生成します。
timer.Enabled = True
End Sub
Private Sub CreateReport(ByVal sender As Object, ByVal e As EventArgs)
' タイマ・メソッドが今後発生しないようにします。
timer.Enabled = False
' レポート生成処理。
Dim rpt As New SectionReport1()
Me.viewer1.Document = rpt.Document
rpt.Run(True)
End Sub
|
|
C#
| C#コード |
コードのコピー
|
|---|---|
private Timer timer = new Timer();
private void Form1_Load(object sender, System.EventArgs e)
{
// タイマ・メソッドの作成します。
timer.Tick += new EventHandler(CreateReport);
timer.Interval = 100;
// Loadイベントが終了してから0.1秒後にレポートを生成します。
|
|