This topic has not yet been rated - Rate this topic

How to: Resize Controls Within Worksheet Cells

When you resize columns or rows on a worksheet, any host controls contained in the cells automatically resize to the height or width of the cell that was resized. Windows Forms controls do not resize automatically by default.

Applies to: The information in this topic applies to document-level projects for Excel 2013 and Excel 2010. For more information, see Features Available by Office Application and Project Type.

If you add the controls at design time, you must set positioning options for each control.

If you add a Windows Forms control programmatically and supply a range argument, the control automatically resizes when a cell within the range is resized. For more information, see Adding Controls to Office Documents at Run Time.

To make controls resize with cells at design time

  1. From the Toolbox, drag a Windows Forms control to a worksheet.

  2. Right-click the control, and then click Format Control.

  3. In the Format Control dialog box, click the Properties tab.

  4. Under Object Positioning, select the Move and size with cells option, and then click OK.

    When you resize the cell that contains the control, the control resizes to fit the cell.

If you add a Windows Forms control at run time and pass in a Microsoft.Office.Interop.Excel.Range as the location for the control, the control will automatically resize when the worksheet cell that contains the range is resized.

To make controls resize with cells at run time

  • Add a control to range A1.

    Microsoft.Office.Tools.Excel.Controls.Button control1 =
        this.Controls.AddButton(this.Range["A1"], "control1");
    

    When you resize the cell that contains the control, the control resizes to fit the cell.

You can reset the placement and resizing of the control by setting the Placement property to one of the following XlPlacement values:

To change the behavior of a control so that it does not resize or move with the cell

  • Call the placement property of the control and set the value to xlFreeFloating.

    control1.Placement = Microsoft.Office.Interop.Excel.XlPlacement.xlFreeFloating;
    
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.