Back to Devexpress

IXtraResizableControl Interface

windowsforms-devexpress-dot-utils-dot-controls.md

latest7.2 KB
Original Source

IXtraResizableControl Interface

Defines an interface a control that can be implemented to provide layout information to a Layout Control.

Namespace : DevExpress.Utils.Controls

Assembly : DevExpress.Utils.v25.2.dll

NuGet Packages : DevExpress.Utils, DevExpress.Wpf.Core

Declaration

csharp
public interface IXtraResizableControl
vb
Public Interface IXtraResizableControl

Remarks

The Layout Control is the control that provides advanced capabilities to create, customize and maintain a consistent layout of controls within a form. It maintains consistent control layouts, supports layout customization, the automatic control resizing feature, etc.

When a control is added to a Layout Control, a layout item is created that displays this control. The layout item can also display a label next to the control. A control can implement the IXtraResizableControl interface to provide layout information used to initialize the corresponding layout item’s specific settings. This includes the control’s default size constraints and whether the layout item’s label should be visible by default.

Default size constraints are supplied via the IXtraResizableControl.MinSize and IXtraResizableControl.MaxSize properties. If the default size constraints are additionally customized for a control from its MaximumSize and MinimumSize properties, the actual default size constraints are calculated according to the OptionsView.ControlDefaultMaxSizeCalcMode and OptionsView.ControlDefaultMinSizeCalcMode options.

The default visibility of the layout item’s label is specified by the IXtraResizableControl.IsCaptionVisible property. This property’s value is used to initialize the BaseLayoutItem.TextVisible property. It’s possible to change the BaseLayoutItem.TextVisible after the layout item has been created.

Most DevExpress editors provide layout information via the IXtraResizableControl interface. You can implement this interface for a custom control to allow it to communicate with the Layout Control.

Example

The following example demonstrates a button control (the SimpleButton control’s descendant) implementing the IXtraResizableControl interface. Size constraints retrieved via the IXtraResizableControl.MaxSize and IXtraResizableControl.MinSize properties prevent the button from being resized. The button’s maximum and minimum sizes are set to a value of an inherited SizeableMinSize property. This property return the minimum size required to display the text in its entirety. When the button’s text changes, the SizeableMinSize property is recalculated automatically, and it’s only required to fire the IXtraResizableControl.Changed event to notify subscribers of the changes.

Note that the SimpleButton control already implements the IXtraResizableControl interface. So this example is only given for demonstration purposes.

csharp
using DevExpress.XtraEditors;
using DevExpress.Utils.Controls;

public class MySimpleButton : SimpleButton, IXtraResizableControl {
    bool IXtraResizableControl.IsCaptionVisible { get { return false; } }
    Size IXtraResizableControl.MinSize { get { return SizeableMinSize; } }
    Size IXtraResizableControl.MaxSize { get { return SizeableMinSize; } }
    private static readonly object layoutInfoChanged = new object();      
    event EventHandler IXtraResizableControl.Changed {
        add { Events.AddHandler(layoutInfoChanged, value); }
        remove { Events.RemoveHandler(layoutInfoChanged, value); }
    }        
    protected void RaiseChanged() {
        EventHandler changed = (EventHandler)Events[layoutInfoChanged];
        if (changed == null) return;
        changed(this, EventArgs.Empty);
    }
    public override string Text {
        get {
            return base.Text;
        }
        set {
            base.Text = value;
            RaiseChanged();
        }
    }
}
vb
Imports DevExpress.Utils.Controls
Imports DevExpress.XtraEditors

Public Class MySimpleButton
    Inherits SimpleButton
    Implements IXtraResizableControl
    Private ReadOnly Property IsCaptionVisible() As Boolean _
    Implements IXtraResizableControl.IsCaptionVisible
        Get
            Return False
        End Get
    End Property
    Private ReadOnly Property MinSize() As Size Implements IXtraResizableControl.MinSize
        Get
            Return SizeableMinSize
        End Get
    End Property
    Private ReadOnly Property MaxSize() As Size Implements IXtraResizableControl.MaxSize
        Get
            Return SizeableMinSize
        End Get
    End Property
    Private Shared ReadOnly layoutInfoChanged As Object = New Object()
    Private Custom Event Changed As EventHandler Implements IXtraResizableControl.Changed
        AddHandler(ByVal value As EventHandler)
            Events.AddHandler(layoutInfoChanged, value)
        End AddHandler
        RemoveHandler(ByVal value As EventHandler)
            Events.RemoveHandler(layoutInfoChanged, value)
        End RemoveHandler
        RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim handler As EventHandler = CType(Events(layoutInfoChanged), EventHandler)
            If handler Is Nothing Then Return
            handler(sender, e)
        End RaiseEvent
    End Event

    Public Overrides Property Text() As String
        Get
            Return MyBase.Text
        End Get
        Set(ByVal value As String)
            MyBase.Text = Value
            RaiseEvent Changed(Me, EventArgs.Empty)
        End Set
    End Property
End Class

See Also

IXtraResizableControl Members

DevExpress.Utils.Controls Namespace