Back to Devexpress

XRControl.ToImage() Method

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

latest2.8 KB
Original Source

XRControl.ToImage() Method

Returns a graphical representation of a control.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public virtual DXImage ToImage()
vb
Public Overridable Function ToImage As DXImage

Returns

TypeDescription
DXImage

The resulting image.

|

Remarks

Use the ToImage method to obtain an image from any report control. Later, this image can be used to display a control in the Web browser, or saved to a file for future use.

Note

A control can’t be saved to an image if it doesn’t belong to a report. Therefore, if you’re creating a separate report control, first add the control to any report to call the ToImage method.

Example

The following code demonstrates how to use the ToImage method. It first creates a label, sets a couple of its properties, adds it to the label, and then creates an image of the label and saves it to a file.

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

public void CreateControlImage() {
    // Create a label and adjust its properties.
    XRLabel label = new XRLabel();
    label.BackColor = Color.Red;
    label.Text = "XRLabel";

    // Create an empty report and add a label to it.
    XtraReport report = new XtraReport();
    report.Bands.Add(new DetailBand());
    report.Bands[0].Controls.Add(label);

    // Create an image from the label and save it to a disk.
    Image img = label.ToImage();
    img.Save("C:\\output.jpg");
}
vb
Imports System.Drawing
Imports DevExpress.XtraReports.UI
' ...

Public Sub CreateControlImage()
    ' Create a label and adjust its properties.
    Dim label As New XRLabel()
    label.BackColor = Color.Red
    label.Text = "XRLabel"

    ' Create an empty report and add a label to it.
    Dim report As New XtraReport()
    report.Bands.Add(New DetailBand())
    report.Bands(0).Controls.Add(label)

    ' Create an image from the label and save it to a disk.
    Dim img As Image = label.ToImage()
    img.Save("C:\\output.jpg")
End Sub

See Also

XRControl Class

XRControl Members

DevExpress.XtraReports.UI Namespace