作成日: 2013/11/08 最終更新日: 2014/10/15
文書種別
制限事項
詳細
用紙方向が横方向のレポートまたはドキュメントを作成して、C1DocumentViewerの印刷ボタンを選択すると、印刷ダイアログの用紙方向が縦に設定されてしまいます。
この現象は、C1DocumentViewerが継承しているWPF標準のDocumentViewerの動作に基づく制限事項です。この現象はDocumentViewerでも発生します。
DocumentViewerでは印刷ダイアログの用紙設定を変更することができないため、印刷ダイアログを表示すると用紙方向は既定値である縦として設定されてしまいます。
この現象は、C1DocumentViewerが継承しているWPF標準のDocumentViewerの動作に基づく制限事項です。この現象はDocumentViewerでも発生します。
DocumentViewerでは印刷ダイアログの用紙設定を変更することができないため、印刷ダイアログを表示すると用紙方向は既定値である縦として設定されてしまいます。
回避方法
次のようにC1DocumentViewerのテンプレートをカスタマイズして、印刷ボタンクリック時の処理を変更して用紙方向を反映させることで、本現象を回避することが可能です。
◎サンプルコード (Visual Basic)
◎サンプルコード (C#)
◎サンプルコード (Visual Basic)
Public Class MyDocumentViewer
Inherits C1.WPF.C1Report.C1DocumentViewer
Private printbtn As Button
Public ReadOnly Property PrintButton() As Button
Get
Return printbtn
End Get
End Property
Public Overrides Sub OnApplyTemplate()
MyBase.OnApplyTemplate()
Dim cc = TryCast(TryCast(TryCast(VisualTreeHelper.GetChild(Me, 0), Border).Child, Grid).Children(0), ContentControl)
cc.ApplyTemplate()
printbtn = TryCast(TryCast(VisualTreeHelper.GetChild(cc, 0), ToolBar).Items(0), Button)
printbtn.Command = Nothing
End Sub
End Class
AddHandler c1dv.Loaded,
Sub(s, e)
c1dv.ApplyTemplate()
AddHandler c1dv.PrintButton.Click,
Sub(s1, e1)
Dim pd As New System.Windows.Forms.PrintDialog()
pd.Document = rpt.Document
Dim myPrinterSettings As New PrinterSettings()
myPrinterSettings.DefaultPageSettings.Landscape = True
If (rpt.Layout.Orientation = OrientationEnum.Landscape) Then
pd.PrinterSettings.DefaultPageSettings.Landscape = True
Else
pd.PrinterSettings.DefaultPageSettings.Landscape = False
End If
If (pd.ShowDialog() = System.Windows.Forms.DialogResult.OK) Then
pd.Document.Print()
End If
End Sub
End Sub
Inherits C1.WPF.C1Report.C1DocumentViewer
Private printbtn As Button
Public ReadOnly Property PrintButton() As Button
Get
Return printbtn
End Get
End Property
Public Overrides Sub OnApplyTemplate()
MyBase.OnApplyTemplate()
Dim cc = TryCast(TryCast(TryCast(VisualTreeHelper.GetChild(Me, 0), Border).Child, Grid).Children(0), ContentControl)
cc.ApplyTemplate()
printbtn = TryCast(TryCast(VisualTreeHelper.GetChild(cc, 0), ToolBar).Items(0), Button)
printbtn.Command = Nothing
End Sub
End Class
AddHandler c1dv.Loaded,
Sub(s, e)
c1dv.ApplyTemplate()
AddHandler c1dv.PrintButton.Click,
Sub(s1, e1)
Dim pd As New System.Windows.Forms.PrintDialog()
pd.Document = rpt.Document
Dim myPrinterSettings As New PrinterSettings()
myPrinterSettings.DefaultPageSettings.Landscape = True
If (rpt.Layout.Orientation = OrientationEnum.Landscape) Then
pd.PrinterSettings.DefaultPageSettings.Landscape = True
Else
pd.PrinterSettings.DefaultPageSettings.Landscape = False
End If
If (pd.ShowDialog() = System.Windows.Forms.DialogResult.OK) Then
pd.Document.Print()
End If
End Sub
End Sub
◎サンプルコード (C#)
public class MyDocumentViewer : C1.WPF.C1Report.C1DocumentViewer
{
private Button printbtn;
public Button PrintButton
{
get
{
return printbtn;
}
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var cc = (((VisualTreeHelper.GetChild(this, 0) as Border).Child as Grid).Children[0] as ContentControl);
cc.ApplyTemplate();
printbtn = ((VisualTreeHelper.GetChild(cc, 0) as ToolBar).Items[0] as Button);
printbtn.Command = null;
}
}
c1dv.Loaded += (s, e) =>
{
c1dv.ApplyTemplate();
c1dv.PrintButton.Click += (s1, e1) =>
{
System.Windows.Forms.PrintDialog pd = new System.Windows.Forms.PrintDialog();
pd.Document = rpt.Document;
PrinterSettings myPrinterSettings = new PrinterSettings();
myPrinterSettings.DefaultPageSettings.Landscape = true;
if ((rpt.Layout.Orientation == OrientationEnum.Landscape))
{
pd.PrinterSettings.DefaultPageSettings.Landscape = true;
}
else
{
pd.PrinterSettings.DefaultPageSettings.Landscape = false;
}
if ((pd.ShowDialog() == System.Windows.Forms.DialogResult.OK))
{
pd.Document.Print();
}
};
};
{
private Button printbtn;
public Button PrintButton
{
get
{
return printbtn;
}
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var cc = (((VisualTreeHelper.GetChild(this, 0) as Border).Child as Grid).Children[0] as ContentControl);
cc.ApplyTemplate();
printbtn = ((VisualTreeHelper.GetChild(cc, 0) as ToolBar).Items[0] as Button);
printbtn.Command = null;
}
}
c1dv.Loaded += (s, e) =>
{
c1dv.ApplyTemplate();
c1dv.PrintButton.Click += (s1, e1) =>
{
System.Windows.Forms.PrintDialog pd = new System.Windows.Forms.PrintDialog();
pd.Document = rpt.Document;
PrinterSettings myPrinterSettings = new PrinterSettings();
myPrinterSettings.DefaultPageSettings.Landscape = true;
if ((rpt.Layout.Orientation == OrientationEnum.Landscape))
{
pd.PrinterSettings.DefaultPageSettings.Landscape = true;
}
else
{
pd.PrinterSettings.DefaultPageSettings.Landscape = false;
}
if ((pd.ShowDialog() == System.Windows.Forms.DialogResult.OK))
{
pd.Document.Print();
}
};
};
旧文書番号
80547