Skip to main content

How to: Provide Size Constraints for Control via IXtraResizable Interface

  • 2 minutes to read

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.

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;