作成日: 2020/10/23 最終更新日: 2020/10/23
文書種別
使用方法
詳細
Excelライクプレビューで印刷ボタンを押下して印刷処理が終わると、プレビュー画面が再度表示されます。次のような対応をすることで印刷処理後にプレビュー画面を閉じることができます。以下ではPrintPreviewShowingイベントで印刷ボタンを押下した場合にイベントを発生させ、そこでプレビュー画面を閉じています。
◎サンプルコード(VB)
◎サンプルコード(C#)
◎サンプルコード(VB)
Imports FarPoint.Win.Spread
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' 印刷設定
FpSpread1.ActiveSheet.PrintInfo.Preview = True
FpSpread1.ActiveSheet.PrintInfo.EnhancePreview = True
' 印刷の実行
FpSpread1.PrintSheet(FpSpread1.ActiveSheet)
End Sub
Private Sub FpSpread1_PrintPreviewShowing(sender As Object, e As PrintPreviewShowingEventArgs) Handles FpSpread1.PrintPreviewShowing
' 印刷用ボタンのClickイベントハンドラの設定
For Each c As Control In e.PreviewDialog.Controls
If c.Text = "印刷(&P)" Then
RemoveHandler c.Click, AddressOf PrintButton_Click
AddHandler c.Click, AddressOf PrintButton_Click
End If
Next
End Sub
Private Sub PrintButton_Click(sender As Object, e As EventArgs)
' 印刷プレビューダイアログのクローズ
DirectCast(DirectCast(sender, Control).Parent, PrintPreviewDialog).Close()
End Sub
End Class
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' 印刷設定
FpSpread1.ActiveSheet.PrintInfo.Preview = True
FpSpread1.ActiveSheet.PrintInfo.EnhancePreview = True
' 印刷の実行
FpSpread1.PrintSheet(FpSpread1.ActiveSheet)
End Sub
Private Sub FpSpread1_PrintPreviewShowing(sender As Object, e As PrintPreviewShowingEventArgs) Handles FpSpread1.PrintPreviewShowing
' 印刷用ボタンのClickイベントハンドラの設定
For Each c As Control In e.PreviewDialog.Controls
If c.Text = "印刷(&P)" Then
RemoveHandler c.Click, AddressOf PrintButton_Click
AddHandler c.Click, AddressOf PrintButton_Click
End If
Next
End Sub
Private Sub PrintButton_Click(sender As Object, e As EventArgs)
' 印刷プレビューダイアログのクローズ
DirectCast(DirectCast(sender, Control).Parent, PrintPreviewDialog).Close()
End Sub
End Class
◎サンプルコード(C#)
private void button1_Click(object sender, EventArgs e)
{
//印刷設定
fpSpread1.ActiveSheet.PrintInfo.Preview = true;
fpSpread1.ActiveSheet.PrintInfo.EnhancePreview = true;
//印刷の実行
fpSpread1.PrintSheet(fpSpread1.ActiveSheet);
}
private void fpSpread1_PrintPreviewShowing(object sender,FarPoint.Win.Spread.PrintPreviewShowingEventArgs e)
{
foreach (Control c in e.PreviewDialog.Controls) {
if (c.Text == "印刷(&P)"){
c.Click -= PrintButton_Click;
c.Click += PrintButton_Click;
}
}
}
private void PrintButton_Click(object sender, EventArgs e)
{
((PrintPreviewDialog)((Control)sender).Parent).Close();
}
{
//印刷設定
fpSpread1.ActiveSheet.PrintInfo.Preview = true;
fpSpread1.ActiveSheet.PrintInfo.EnhancePreview = true;
//印刷の実行
fpSpread1.PrintSheet(fpSpread1.ActiveSheet);
}
private void fpSpread1_PrintPreviewShowing(object sender,FarPoint.Win.Spread.PrintPreviewShowingEventArgs e)
{
foreach (Control c in e.PreviewDialog.Controls) {
if (c.Text == "印刷(&P)"){
c.Click -= PrintButton_Click;
c.Click += PrintButton_Click;
}
}
}
private void PrintButton_Click(object sender, EventArgs e)
{
((PrintPreviewDialog)((Control)sender).Parent).Close();
}
旧文書番号
86117