xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xrcontrol-58f870dd.md
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.v25.2.dll
NuGet Package : DevExpress.Reporting.Core
[Browsable(false)]
[DefaultValue(false)]
[SRCategory(ReportStringId.CatBehavior)]
public virtual bool CanShrink { get; set; }
<SRCategory(ReportStringId.CatBehavior)>
<Browsable(False)>
<DefaultValue(False)>
Public Overridable Property CanShrink As Boolean
| Type | Default | Description |
|---|---|---|
| Boolean | false |
true , if the control’s height can decrease in order to remove unused space; otherwise, false.
|
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.
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.
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);
}
}
Imports System.Drawing
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraPrinting
' ...
Public Partial Class XtraReport1
Inherits XtraReport
Public Function CreateXRLabel() As XRLabel
' Create a new label object.
Dim label As 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
End Function
Public Sub New()
' ...
' Add the label to the report's Detail band.
Dim label As XRLabel = CreateXRLabel()
Me.Detail.Controls.Add(label)
End Sub
End Class
See Also