这个示例展示了如何重置控件的外观属性值 (例如 XRControl.BackColor、XRControl.ForeColor、XRControl.Borders、XRControl.Font 等等)。 当这些属性值被在报表控件中设置、但后来应从控件的父对象获取它们的取值时,就需要重置。 要学习更多关于重写外观属性值的内容,请参阅 外观属性 文档。
C# | 复制代码 |
---|
using System.Drawing;
using System.Drawing.Printing;
using DevExpress.XtraReports.UI;
private void xrLabel2_BeforePrint(object sender, PrintEventArgs e) {
SetCustomStyle((XRLabel)sender);
}
private void xrLabel3_BeforePrint(object sender, PrintEventArgs e) {
SetCustomStyle((XRLabel)sender);
ResetStyle((XRLabel)sender);
}
private void SetCustomStyle(XRLabel label) {
label.BackColor = Color.Red;
label.BorderColor = Color.Blue;
label.Borders = DevExpress.XtraPrinting.BorderSide.All;
label.BorderWidth = 5;
label.Font = new Font(label.Font, FontStyle.Bold);
label.ForeColor = Color.White;
label.Padding = 10;
label.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
}
private void ResetStyle(XRLabel label) {
label.ResetBackColor();
label.ResetBorderColor();
label.ResetBorders();
label.ResetBorderWidth();
label.ResetFont();
label.ResetForeColor();
label.ResetPadding();
label.ResetTextAlignment();
}
|
Visual Basic | 复制代码 |
---|
Imports System.Drawing
Imports System.Drawing.Printing
Imports DevExpress.XtraReports.UI
Private Sub xrLabel2_BeforePrint(ByVal sender As Object, ByVal e As PrintEventArgs) _
Handles xrLabel2.BeforePrint
SetCustomStyle(CType(sender, XRLabel))
End Sub
Private Sub xrLabel3_BeforePrint(ByVal sender As Object, ByVal e As PrintEventArgs) _
Handles xrLabel3.BeforePrint
SetCustomStyle(CType(sender, XRLabel))
ResetStyle(CType(sender, XRLabel))
End Sub
Private Sub SetCustomStyle(ByVal label As XRLabel)
label.BackColor = Color.Red
label.BorderColor = Color.Blue
label.Borders = DevExpress.XtraPrinting.BorderSide.All
label.BorderWidth = 5
abel.Font = New Font(label.Font, FontStyle.Bold)
label.ForeColor = Color.White
label.Padding = 10
label.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter
End Sub
Private Sub ResetStyle(ByVal label As XRLabel)
label.ResetBackColor()
label.ResetBorderColor()
label.ResetBorders()
label.ResetBorderWidth()
label.ResetFont()
label.ResetForeColor()
label.ResetPadding()
label.ResetTextAlignment()
End Sub
|
参阅