Back to Devexpress

XRControl.Font Property

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

latest9.9 KB
Original Source

XRControl.Font Property

Gets or sets the control’s font.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
[SRCategory(ReportStringId.CatAppearance)]
[XRLocalizable(true)]
public virtual DXFont Font { get; set; }
vb
<SRCategory(ReportStringId.CatAppearance)>
<XRLocalizable(True)>
Public Overridable Property Font As DXFont

Property Value

TypeDescription
DXFont

An object that contains font information.

|

Remarks

The Font property specifies the font of the control’s XRControl.Text, while the text alignment is specified by the XRControl.TextAlignment property.

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

Note

The Font property is used only by some descendants of the XRControl class. For example, the XRPageBreak class ignores the Font 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 Font 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-wpf-create-report-in-code/CS/RuntimeReportsApplication/MainWindow.xaml.cs#L75

csharp
XRLabel label = new XRLabel();
label.Font = new DXFont("Tahoma", 12, DXFontStyle.Bold);
label.Text = caption;

reporting-mvc-generate-report-dynamically-for-specified-query/CS/ReportForQueryExample/PredefinedReports/TestReport.cs#L36

csharp
label.Width = 500;
label.Font = new System.Drawing.Font("Verdana", 10F, FontStyle.Bold);
this.Bands[BandKind.PageHeader].Controls.Add(label);

reporting-winforms-sql-data-source-runtime/CS/RuntimeSqlDataSourceReportSample/ReportCreator.cs#L41

csharp
XRLabel label = new XRLabel();
label.Font = new DXFont("Tahoma", 12, DXFontStyle.Bold);
label.Text = caption;

reporting-web-forms-handle-server-side-errors/CS/DXWebApplication1/Reports/XtraReport3.cs#L73

csharp
this.Detail});
this.Font = new DevExpress.Drawing.DXFont("Arial", 9.75F);
this.Version = "18.2";

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

csharp
label.BorderWidth = 0.5f;
label.Font = new Font(label.Parent.Font, FontStyle.Bold);
label.ForeColor = Color.White;

reporting-wpf-create-report-in-code/VB/RuntimeReportsApplication/MainWindow.xaml.vb#L84

vb
Dim label As New XRLabel()
label.Font = New DXFont("Tahoma", 12, DXFontStyle.Bold)
label.Text = caption

reporting-winforms-sql-data-source-runtime/VB/RuntimeSqlDataSourceReportSample/ReportCreator.vb#L38

vb
Dim label As New XRLabel()
label.Font = New DXFont("Tahoma", 12, DXFontStyle.Bold)
label.Text = caption

reporting-web-forms-handle-server-side-errors/VB/DXWebApplication1/Reports/XtraReport3.vb#L68

vb
Me.Bands.AddRange(New DevExpress.XtraReports.UI.Band() { Me.TopMargin, Me.BottomMargin, Me.Detail})
Me.Font = New DevExpress.Drawing.DXFont("Arial", 9.75F)
Me.Version = "18.2"

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

vb
label.BorderWidth = 0.5F
label.Font = New Font(label.Parent.Font, FontStyle.Bold)
label.ForeColor = Color.White

reporting-wpf-use-private-custom-font-distributed-with-application/VB/PrivateFontDemo/MainWindow.xaml.vb#L29

vb
Dim report = New SampleReport()
report.Font = New DXFont("Miss Fajardose", 48.0F, DXFontStyle.Regular, DXGraphicsUnit.Point)
Dim cachedReportSource = New CachedReportSource(report, New MemoryDocumentStorage())

See Also

Appearance Properties

Report Visual Styles

Conditionally Change the Control's Appearance

XRControl Class

XRControl Members

DevExpress.XtraReports.UI Namespace