[FAQ] Resizing Windows Programmatically

Question

I’m setting _glueWindow.Bounds in my .NET app, but the visual size of the Glue window doesn’t update, even though the value changes in the debugger. Why?

Answer

Use MoveResize, which will work in both Web and Classic groups:

_glueWindow.Update(u => u.MoveResize(mro => mro.Bounds = newBounds));

Question

When I use MoveResize, the Glue window’s final dimensions don’t match the size I passed in. What causes this?

Answer

The Glue window includes frame decorations (header/caption bar, tab/flat chrome) that add to the overall dimensions beyond the content area. You can calculate decoration offsets before resizing, then add them back when computing new bounds:

// Calculate decoration offsets (do this before the layout switch)
 var glueWindowBounds = _glueWindow.Bounds;
_verticalDecorations = glueWindowBounds.Height - _layout.Size.Height;
_horizontalDecorations = glueWindowBounds.Width - _layout.Size.Width;

Then when layout size changes, the new Glue window bounds will be:

var glueWindowBounds = _glueWindow.Bounds;
var newWidth = _layout.Size.Width + _horizontalDecorations;
var newHeight = _layout.Size.Height + _verticalDecorations;
var newBounds = new Bounds
{
    Left = glueWindowBounds.X,
    Top = glueWindowBounds.Y,
    Width = newWidth,
    Height = newHeight
};

And MoveResize should be used to change the bounds:

_glueWindow.Update(u => u.MoveResize(mro => mro.Bounds = newBounds));

Question

My .NET view uses AutoSize and changes size dynamically (e.g., when the user switches tabs). Can the Glue window resize to match?

Answer

You can subscribe to the SizeChanged event of an inner layout control (such as a TableLayoutPanel) and then call MoveResize with recalculated bounds including decoration offsets (as shown above). If you don’t have direct access to inner layout controls, you can traverse the control tree to locate the relevant component.