This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
/
XtraReport1.cs
51 lines (47 loc) · 2 KB
/
XtraReport1.cs
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
using System;
using System.Drawing;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
namespace WindowsApplication1 {
public partial class XtraReport1 : XtraReport {
public XtraReport1() {
InitializeComponent();
PrintingSystem.AfterMarginsChange +=
new MarginsChangeEventHandler(PrintingSystem_AfterMarginsChange);
PrintingSystem.PageSettingsChanged +=
new EventHandler(PrintingSystem_PageSettingsChanged);
}
void PrintingSystem_PageSettingsChanged(object sender, EventArgs e) {
ChangeReportSettings(sender);
}
void PrintingSystem_AfterMarginsChange(object sender, MarginsChangeEventArgs e) {
ChangeReportSettings(sender);
}
private void ChangeReportSettings(object sender) {
PrintingSystemBase ps = sender as PrintingSystemBase;
bool isLocationChanged = false;
int newPageWidth =
ps.PageBounds.Width - ps.PageMargins.Left - ps.PageMargins.Right;
int currentPageWidth =
this.PageWidth - this.Margins.Left - this.Margins.Right;
int shift = currentPageWidth - newPageWidth;
foreach (Band _band in base.Bands) {
foreach (XRControl _control in _band.Controls) {
isLocationChanged = true;
_control.Location =
new Point((_control.Location.X - shift), _control.Location.Y);
}
}
if (isLocationChanged == true) {
Margins.Top = ps.PageMargins.Top;
Margins.Bottom = ps.PageMargins.Bottom;
Margins.Left = ps.PageMargins.Left;
Margins.Right = ps.PageMargins.Right;
PaperKind = ps.PageSettings.PaperKind;
PaperName = ps.PageSettings.PaperName;
Landscape = ps.PageSettings.Landscape;
CreateDocument();
}
}
}
}