//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["A1"].Value = "Original controls"; worksheet.Range["A:A,C:C"].ColumnWidthInPixel = 121.0D; var controls = worksheet.Controls; var ctl1 = controls.AddButton(4.9, 21.6, 127.85, 24.4); ctl1.Text = "Sample button"; ctl1.PrintObject = true; var ctl2 = controls.AddCheckBox(5.5, 51.5, 121.25, 16.5); ctl2.Text = "Sample check box"; var ctl3 = controls.AddScrollBar(6.8, 79.7, 121.95, 17.30); // Form controls are also shapes. Some features of shapes are available to form controls. // Example 1: Get a button from shapes collection foreach (var shp in worksheet.Shapes) { if (shp.Type != ShapeType.FormControl) { continue; } if (shp.Control.FormControlType == Forms.FormControlType.Button) { Console.WriteLine("Found the sample button. The shape name is " + shp.Name); break; } } // Example 2: Duplicate the scroll bar shape var scrollbarShape = ctl3.ShapeRange[0]; var scrollbar2Shape = scrollbarShape.Duplicate(); // Example 3: Copy shapes on cells IRange bottomRightCell = scrollbar2Shape.BottomRightCell; var copyFrom = worksheet.Range[0, 0, bottomRightCell.Row + 1, bottomRightCell.Column + 1]; var copyTo = worksheet.Range[0, bottomRightCell.ColumnCount + 1, bottomRightCell.Row, bottomRightCell.Column]; copyFrom.Copy(copyTo); copyTo[0, 0].Value = "Copied controls"; // Save to an excel file workbook.Save("ShapeOfFormControl.xlsx");
' Create a new Workbook Dim workbook As New Workbook Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.Range!A1.Value = "Original controls" worksheet.Range("A:A,C:C").ColumnWidthInPixel = 121.0R Dim controls = worksheet.Controls Dim ctl1 = controls.AddButton(4.9, 21.6, 127.85, 24.4) ctl1.Text = "Sample button" ctl1.PrintObject = True Dim ctl2 = controls.AddCheckBox(5.5, 51.5, 121.25, 16.5) ctl2.Text = "Sample check box" Dim ctl3 = controls.AddScrollBar(6.8, 79.7, 121.95, 17.3) ' Form controls are also shapes. Some features of shapes are available to form controls. ' Example 1: Get a button from shapes collection For Each shp In worksheet.Shapes If shp.Type <> ShapeType.FormControl Then Continue For If shp.Control.FormControlType = Forms.FormControlType.Button Then Console.WriteLine("Found the sample button. The shape name is " & shp.Name) Exit For End If Next ' Example 2: Duplicate the scroll bar shape Dim scrollbarShape = ctl3.ShapeRange(0) Dim scrollbar2Shape = scrollbarShape.Duplicate() ' Example 3: Copy shapes on cells Dim bottomRightCell As IRange = scrollbar2Shape.BottomRightCell Dim copyFrom = worksheet.Range(0, 0, bottomRightCell.Row + 1, bottomRightCell.Column + 1) Dim copyTo = worksheet.Range(0, bottomRightCell.ColumnCount + 1, bottomRightCell.Row, bottomRightCell.Column) copyFrom.Copy(copyTo) copyTo(0, 0).Value = "Copied controls" ' save to an excel file workbook.Save("ShapeOfFormControl.xlsx")