-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathViewerForm.cs
More file actions
141 lines (123 loc) · 5.11 KB
/
ViewerForm.cs
File metadata and controls
141 lines (123 loc) · 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
namespace LijsDev.CrystalReportsRunner;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Windows.Forms;
using LijsDev.CrystalReportsRunner.Core;
internal partial class ViewerForm : Form
{
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
private readonly bool _closeOnEscapeKey;
public ViewerForm(ReportDocument document, ReportViewerSettings viewerSettings)
{
InitializeComponent();
// Set Icon
if (viewerSettings.WindowIcon is not null)
{
try
{
using var ms = new MemoryStream(viewerSettings.WindowIcon);
var iconBitmap = new Bitmap(ms);
Icon = Icon.FromHandle(iconBitmap.GetHicon());
}
catch (Exception ex)
{
// TODO: Communicate to caller app the error in a better way. For now, the log will do.
Logger.Fatal(ex);
}
}
// Configure Form
_closeOnEscapeKey = viewerSettings.WindowCloseOnEscapeKey;
ShowInTaskbar = viewerSettings.WindowShowInTaskbar;
if (viewerSettings.WindowMinimumWidth is not null && viewerSettings.WindowMinimumHeight is not null)
{
MinimumSize = new Size(viewerSettings.WindowMinimumWidth.Value, viewerSettings.WindowMinimumHeight.Value);
}
if (viewerSettings.WindowMaximumWidth is not null && viewerSettings.WindowMaximumHeight is not null)
{
MaximumSize = new Size(viewerSettings.WindowMaximumWidth.Value, viewerSettings.WindowMaximumHeight.Value);
}
if (viewerSettings.WindowLocationHeight is not null)
{
Height = viewerSettings.WindowLocationHeight.Value;
}
if (viewerSettings.WindowLocationWidth is not null)
{
Width = viewerSettings.WindowLocationWidth.Value;
}
if (viewerSettings.WindowLocationLeft is not null)
{
Left = viewerSettings.WindowLocationLeft.Value;
}
if (viewerSettings.WindowLocationTop is not null)
{
Top = viewerSettings.WindowLocationTop.Value;
}
MinimizeBox = viewerSettings.WindowAllowMinimize;
MaximizeBox = viewerSettings.WindowAllowMaximize;
WindowState = (FormWindowState)viewerSettings.WindowInitialState;
StartPosition = (FormStartPosition)viewerSettings.WindowInitialPosition;
// Resize disabled
if (!viewerSettings.WindowAllowResize)
{
FormBorderStyle = FormBorderStyle.FixedSingle;
}
// Set report
crystalReportViewer1.ReportSource = document;
// Configure Crystal Report Viewer
if (!viewerSettings.ShowReportTabs)
{
SetReportTabsVisible(false);
}
if (viewerSettings.UICultureLCID is not null)
{
crystalReportViewer1.SetProductLocale(viewerSettings.UICultureLCID.Value);
}
crystalReportViewer1.AllowedExportFormats = (int)viewerSettings.AllowedExportFormats;
crystalReportViewer1.ShowRefreshButton = viewerSettings.ShowRefreshButton;
crystalReportViewer1.ShowGroupTreeButton = viewerSettings.ShowGroupTreeButton;
crystalReportViewer1.ShowParameterPanelButton = viewerSettings.ShowParameterPanelButton;
crystalReportViewer1.ToolPanelView = (ToolPanelViewType)(int)viewerSettings.ToolPanelView;
crystalReportViewer1.EnableDrillDown = viewerSettings.EnableDrillDown;
crystalReportViewer1.EnableRefresh = viewerSettings.EnableRefresh;
crystalReportViewer1.ShowCopyButton = viewerSettings.ShowCopyButton;
crystalReportViewer1.ShowCloseButton = viewerSettings.ShowCloseButton;
crystalReportViewer1.ShowPrintButton = viewerSettings.ShowPrintButton;
crystalReportViewer1.ShowExportButton = viewerSettings.ShowExportButton;
crystalReportViewer1.ShowZoomButton = viewerSettings.ShowZoomButton;
if (viewerSettings.ZoomLevel is not 100)
{
crystalReportViewer1.Zoom(viewerSettings.ZoomLevel);
}
}
protected override bool ProcessDialogKey(Keys keyData)
{
if (_closeOnEscapeKey && ModifierKeys is Keys.None && keyData is Keys.Escape)
{
Close();
return true;
}
return base.ProcessDialogKey(keyData);
}
private void SetReportTabsVisible(bool visible)
{
foreach (Control control in crystalReportViewer1.Controls)
{
if ((control is PageView view) && (control.Controls.Count > 0))
{
var tab = (TabControl)view.Controls[0];
if (!visible)
{
tab.ItemSize = new Size(0, 1);
tab.SizeMode = TabSizeMode.Fixed;
tab.Appearance = TabAppearance.Buttons;
}
else
{
tab.ItemSize = new Size(67, 18);
tab.SizeMode = TabSizeMode.Normal;
tab.Appearance = TabAppearance.Normal;
}
}
}
}
}