XRControl.CanShrink Property
Gets or sets a value that determines whether the height of a control can decrease if its content does not completely fill the control.
Namespace: DevExpress.XtraReports.UI
Assembly: DevExpress.XtraReports.v24.2.dll
NuGet Package: DevExpress.Reporting.Core
Declaration
[Browsable(false)]
[DefaultValue(false)]
[SRCategory(ReportStringId.CatBehavior)]
public virtual bool CanShrink { get; set; }
Property Value
Type | Default | Description |
---|---|---|
Boolean | false | true, if the control’s height can decrease in order to remove unused space; otherwise, false. |
Remarks
When the CanShrink
is true
, the control’s height can automatically decrease to fit its contents. All other report elements below the current control are moved up to avoid empty space.
If another control overlaps the shrinking control by even one pixel, it will not move up.
Borders remain visible when content is resized if CanShrink property is enabled and XRControl.Text property value is Empty. To hide a control along with its boundaries, set its ProcessNullValues
or ProcessDuplicates
property to ValueSuppressType.SuppressAndShrink.
Limitations
The CanGrow and CanShrink
property values are ignored if the AnchorVertical property is set to Bottom or Both.
The CanShrink
function has no effect if there are other controls to the right or left of the controls that are being shrunk.
The CanShrink
value has no effect for certain report controls, such as the Band class descendants or XRCrossTab control.
Example
The code sample below illustrates how to create an XRLabel object and bind it to data. You should bind your report to the Northwind database’s Products table for this example to work properly.
To learn about the events available for a report and its controls, see Report Events.
using System;
using System.Drawing;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...
public partial class XtraReport1 : XtraReport {
public XRLabel CreateXRLabel() {
// Create a new label object.
XRLabel label = new XRLabel();
// Bind the label to the UnitPrice data field.
// Change the label's foreground color depending on the UnitPrice data field value.
label.ExpressionBindings.AddRange(new ExpressionBinding[] {
new ExpressionBinding("BeforePrint", "Text", "[UnitPrice]"),
new ExpressionBinding("BeforePrint", "ForeColor", "Iif([UnitPrice]>20, \'Red\', \'Green\')")});
// Apply a currency format to the label's text.
label.TextFormatString = "{0:c2}";
// Automatically adjust the label's width to its content.
label.AutoWidth = true;
// Align the label's text to the bottom right corner.
label.TextAlignment = TextAlignment.BottomRight;
return label;
}
public XtraReport1() {
// ...
// Add the label to the report's Detail band.
XRLabel label = CreateXRLabel();
this.Detail.Controls.Add(label);
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CanShrink 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.