Back to Devexpress

XRControl.ResetBorderColor() Method

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xrcontrol-b302d271.md

latest7.7 KB
Original Source

XRControl.ResetBorderColor() Method

Resets the XRControl.BorderColor property value, so that it is no longer stored in the current control and is obtained from its parent instead.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public void ResetBorderColor()
vb
Public Sub ResetBorderColor

Remarks

If the XRControl.BorderColor property’s value is not set for the current report control, its value is obtained from its parent, or a parent of its parent and so on. So, if it is set in the current control, it starts overriding its parent’s BorderColor property value.

Then, if it is necessary to remove the current control’s BorderColor property value and start using its parent’s BorderColor again, you can right-click the Properties window at design time and choose the Reset option, as shown in the image below.

And the ResetBorderColor method is intended to do the same action at runtime.

Example

This code snippet assigns custom appearance settings to report labels. The ResetStyle method clears the appearance settings of the control. This makes the control use the values from the parent control’s settings.

View Example: Reporting for WinForms - Appearance Settings, Styles, Style Priority

csharp
using System;
using System.Drawing;
using System.Drawing.Printing;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;

public partial class XtraReport1 : XtraReport {
    public XtraReport1() {
        InitializeComponent();

        XRControlStyle myStyle = new XRControlStyle {
            Name = "MyStyle1",
            BackColor = Color.LightBlue,
            BorderColor = Color.LightGray,
            Borders = BorderSide.Top,
            BorderWidth = 2f,
            Font = new Font("Segoe Script", 16),
            ForeColor = Color.Green,
            TextAlignment = TextAlignment.TopCenter,

    };
        this.StyleSheet.Add(myStyle);
    }

    private void xrLabel1_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e) {
        ((XRLabel)sender).StyleName = "MyStyle1";

    }
    private void XrLabel2_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e) {
        ApplyAppearanceSettings((XRLabel)sender);
    }

    private void XrLabel3_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e) {
        ApplyAppearanceSettings((XRLabel)sender);
        ResetStyle((XRLabel)sender);
    }

    // Assign custom appearance settings to a control.
    private void ApplyAppearanceSettings(XRLabel label) {
        label.BackColor = Color.Orange;
        label.BorderColor = Color.DarkGray;
        label.Borders = BorderSide.All;
        label.BorderWidth = 0.5f;
        label.Font = new Font(label.Parent.Font, FontStyle.Bold);
        label.ForeColor = Color.White;
        label.TextAlignment = TextAlignment.MiddleRight;
    }

    // Reset appearance settings and use parent control settings.
    private void ResetStyle(XRLabel label) {
        label.ResetBackColor();
        label.ResetBorderColor();
        label.ResetBorders();
        label.ResetBorderWidth();
        label.ResetFont();
        label.ResetForeColor();
        label.ResetPadding();
        label.ResetTextAlignment();
    }
}
vb
Imports System
Imports System.Drawing
Imports System.Drawing.Printing
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraReports.UI

Partial Public Class XtraReport1
    Inherits XtraReport

    Public Sub New()
        InitializeComponent()

        Dim myStyle As XRControlStyle = New XRControlStyle With {
            .Name = "MyStyle1",
            .BackColor = Color.LightBlue,
            .BorderColor = Color.LightGray,
            .Borders = BorderSide.Top,
            .BorderWidth = 2.0F,
            .Font = New Font("Segoe Script", 16),
            .ForeColor = Color.Green,
            .TextAlignment = TextAlignment.TopCenter
        }
        Me.StyleSheet.Add(myStyle)
    End Sub

    Private Sub XrLabel1_BeforePrint(sender As Object, e As ComponentModel.CancelEventArgs) Handles xrLabel1.BeforePrint
        DirectCast(sender, XRLabel).StyleName = "MyStyle1"

    End Sub
    Private Sub XrLabel2_BeforePrint(sender As Object, e As ComponentModel.CancelEventArgs) Handles xrLabel2.BeforePrint
        ApplyAppearanceSettings(DirectCast(sender, XRLabel))
    End Sub

    Private Sub XrLabel4_BeforePrint(sender As Object, e As ComponentModel.CancelEventArgs) Handles xrLabel3.BeforePrint
        ApplyAppearanceSettings(DirectCast(sender, XRLabel))
        ResetStyle(DirectCast(sender, XRLabel))
    End Sub

    ' Assign custom appearance settings to a control.
    Private Sub ApplyAppearanceSettings(ByVal label As XRLabel)
        label.BackColor = Color.Orange
        label.BorderColor = Color.DarkGray
        label.Borders = BorderSide.All
        label.BorderWidth = 0.5F
        label.Font = New Font(label.Parent.Font, FontStyle.Bold)
        label.ForeColor = Color.White
        label.TextAlignment = TextAlignment.MiddleRight
    End Sub

    ' Reset appearance settings and use the parent control settings.
    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
End Class

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ResetBorderColor() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

reporting-winforms-appearance-settings/CS/XtraReport1.cs#L53

csharp
label.ResetBackColor();
label.ResetBorderColor();
label.ResetBorders();

reporting-winforms-appearance-settings/VB/XtraReport1.vb#L42

vb
label.ResetBackColor()
label.ResetBorderColor()
label.ResetBorders()

See Also

Appearance Properties

XRControl Class

XRControl Members

DevExpress.XtraReports.UI Namespace