Back to Devexpress

XRControl.ForeColor Property

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

latest9.5 KB
Original Source

XRControl.ForeColor Property

Gets or sets the control’s foreground color.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
[SRCategory(ReportStringId.CatAppearance)]
public virtual Color ForeColor { get; set; }
vb
<SRCategory(ReportStringId.CatAppearance)>
Public Overridable Property ForeColor As Color

Property Value

TypeDescription
Color

A Color object that represents the foreground color.

|

Remarks

The ForeColor property specifies the control’s foreground color (e.g. the color of the text in XRLabel or the color of the line in XRLine), while the control’s background color is specified by its XRControl.BackColor property.

If the ForeColor 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. Similarly, the ForeColor value of the current control is applied to all its child report controls (if there are any in its XRControl.Controls collection), if their ForeColor property value is not set. For more information on this concept, please refer to Appearance Properties.

Note

The ForeColor property is used only by some descendants of the XRControl class. For example, the XRPageBreak class ignores the ForeColor property.

Example

This example demonstrates how to use the XRLabel control to create a hyperlink.

The code below creates the XRLabel control, sets up its appearance, and specifies its NavigateUrl and Target properties.

csharp
using System.Drawing;
using DevExpress.XtraReports.UI;
// ...

public XRLabel CreateHyperlink(){
    // Create a label for a hyperlink.
    XRLabel hyperlinkLabel = new XRLabel();

    // Set its main properties.
    hyperlinkLabel.Text = "DevExpress Inc.";
    hyperlinkLabel.Width = 200;
    hyperlinkLabel.ForeColor = Color.Blue;
    hyperlinkLabel.Font = new Font("Tahoma", 12, FontStyle.Underline);

    // Set its URL and target.
    hyperlinkLabel.NavigateUrl = "https://www.devexpress.com/";
    hyperlinkLabel.Target = "_blank";

    return hyperlinkLabel;
}
vb
Imports System.Drawing
Imports DevExpress.XtraReports.UI
' ...

Public Function CreateHyperlink() As XRLabel
    ' Create a label for a hyperlink.
    Dim hyperlinkLabel As XRLabel = New XRLabel()

    ' Set its main properties.
    hyperlinkLabel.Text = "DevExpress Inc."
    hyperlinkLabel.Width = 200
    hyperlinkLabel.ForeColor = Color.Blue
    hyperlinkLabel.Font = New Font("Tahoma", 12, FontStyle.Underline)

    ' Set its URL and target.
    hyperlinkLabel.NavigateUrl = "https://www.devexpress.com/"
    hyperlinkLabel.Target = "_blank"

    Return hyperlinkLabel
End Function

To add the hyperlink to the report’s Detail band, handle the report’s BeforePrint event:

csharp
using DevExpress.XtraReports.UI;
// ...

private void XtraReport1_BeforePrint(object sender, System.ComponentModel.EventArgs e) {
    // Create a new hyperlink and add it to the report's Detail Band.
    Bands.GetBandByType(typeof(DetailBand)).Controls.Add(CreateHyperlink());
}
vb
Imports DevExpress.XtraReports.UI
' ...

Private Sub XtraReport1_BeforePrint(ByVal sender As Object, ByVal e As System.ComponentModel.EventArgs)
    Create a new hyperlink and add it to the report's Detail Band.
    Bands.GetBandByType(GetType(DetailBand)).Controls.Add(CreateHyperlink())
End Sub

The label behaves like a hyperlink in a report’s Print Preview and in a document exported to HTML, PDF, RTF, XLS, and XLSX formats.

The following code snippets (auto-collected from DevExpress Examples) contain references to the ForeColor property.

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-insert-a-shape-control/CS/Form1.cs#L27

csharp
shape.Height = 200;
shape.ForeColor = Color.Brown;
shape.FillColor = Color.Beige;

reporting-winforms-change-label-appearance-in-beforeprint-event-handler/CS/XtraReport1.cs#L20

csharp
if (total < 100) {
    label.ForeColor = Color.White;
    label.BackColor = Color.Red;

winforms-scheduler-print-appointments-using-reports/CS/PrintingViaReports/XtraReport1.cs#L48

csharp
((XRLabel)sender).BackColor = curColor;
    ((XRLabel)sender).ForeColor = curColor;
}

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

csharp
label.Font = new Font(label.Parent.Font, FontStyle.Bold);
label.ForeColor = Color.White;
label.TextAlignment = TextAlignment.MiddleRight;

reporting-winforms-custom-progress-bar-control/CS/ProgressBar.cs#L47

csharp
public ProgressBar() {
    this.ForeColor = SystemColors.Highlight;
}

reporting-winforms-insert-a-shape-control/VB/Form1.vb#L27

vb
shape.Height = 200
shape.ForeColor = Color.Brown
shape.FillColor = Color.Beige

reporting-winforms-change-label-appearance-in-beforeprint-event-handler/VB/XtraReport1.vb#L22

vb
If total < 100 Then
    label.ForeColor = Color.White
    label.BackColor = Color.Red

winforms-scheduler-print-appointments-using-reports/VB/PrintingViaReports/XtraReport1.vb#L50

vb
DirectCast(sender, XRLabel).BackColor = curColor
    DirectCast(sender, XRLabel).ForeColor = curColor
End Sub

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

vb
label.Font = New Font(label.Parent.Font, FontStyle.Bold)
label.ForeColor = Color.White
label.TextAlignment = TextAlignment.MiddleRight

reporting-winforms-custom-progress-bar-control/VB/ProgressBar.vb#L46

vb
Public Sub New()
    Me.ForeColor = SystemColors.Highlight
End Sub

See Also

Appearance Properties

Report Visual Styles

Conditionally Change the Control's Appearance

XRControl Class

XRControl Members

DevExpress.XtraReports.UI Namespace