This example produces the Cross Smart Shape, which is represented by the following image:
The control points (yellow diamonds) will resize the horizontal and vertical cross stripes. The stripes will retain their size when the cross is resized.
C# |
Copy Code
|
---|---|
NSmartShape shape = new NSmartShape(); shape.Name = "Cross"; NShapeSheet sheet = shape.Sheet; // modify the transform sheet.TransformSection.Width.Value = 200; sheet.TransformSection.Height.Value = 200; sheet.TransformSection.Angle.Value = 0; sheet.TransformSection.PinX.Value = 100; sheet.TransformSection.PinY.Value = 100; sheet.TransformSection.LocPinX.Formula = "Width*0.5"; sheet.TransformSection.LocPinY.Formula = "Height*0.5"; // add a geometry NGeometrySection geometry1 = new NGeometrySection("Geometry1", "Geometry1"); sheet.Sections.Add(geometry1); geometry1.AddMoveTo("0", "Height/2-Scratch.Y1"); geometry1.AddLineTo("Width/2-Scratch.X1", "Geometry1.Y1"); geometry1.AddLineTo("Geometry1.X2", "0"); geometry1.AddLineTo("Geometry1.X2+2*Scratch.X1", "0"); geometry1.AddLineTo("Geometry1.X4", "Geometry1.Y2"); geometry1.AddLineTo("Width", "Geometry1.Y1"); geometry1.AddLineTo("Geometry1.X6", "Geometry1.Y1+2*Scratch.Y1"); geometry1.AddLineTo("Geometry1.X4", "Geometry1.Y7"); geometry1.AddLineTo("Geometry1.X4", "Height"); geometry1.AddLineTo("Geometry1.X2", "Geometry1.Y9"); geometry1.AddLineTo("Geometry1.X2", "Geometry1.Y7"); geometry1.AddLineTo("0", "Geometry1.Y7"); geometry1.AddLineTo("Geometry1.X1", "Geometry1.Y1"); // add scratches sheet.ScratchSection = new NScratchSection(); sheet.ScratchSection.AddScratch( new NSingleFormulaCell("ABS(User.ControlX2-Width/2)"), new NSingleFormulaCell("ABS(User.ControlY1-Height/2)"), new NSingleFormulaCell(""), new NSingleFormulaCell(""), new NSingleFormulaCell(""), new NSingleFormulaCell("")); // add users sheet.UserDefinedCellsSection = new NUserDefinedCellsSection(); sheet.UserDefinedCellsSection.AddUserCell("ControlX1", "MAX(0,MIN(Width/2,Controls.X1))"); sheet.UserDefinedCellsSection.AddUserCell("ControlX2", "MAX(0,MIN(Width/2,Controls.X2))"); sheet.UserDefinedCellsSection.AddUserCell("ControlY1", "MAX(0,MIN(Height/2,Controls.Y1))"); sheet.UserDefinedCellsSection.AddUserCell("ControlY2", "MAX(0,MIN(Height/2,Controls.Y2))"); // add controls sheet.ControlsSection = new NControlsSection(); sheet.ControlsSection.AddControl("Width*0", "Height/2-10", true, ControlBehavior.Locked, ControlBehavior.OffsetFromCenter, "First control point"); sheet.ControlsSection.AddControl("Width/2-10", "Height*0", true, ControlBehavior.OffsetFromCenter, ControlBehavior.Locked, "Second control point"); shape.FillStyle = new NColorFillStyle(Color.Honeydew); shape.StrokeStyle = new NStrokeStyle(1, Color.Black); |
Visual Basic |
Copy Code
|
---|---|
Dim shape As New NSmartShape shape.Name = "Cross" Dim sheet As NShapeSheet = shape.Sheet ' modify the transform sheet.TransformSection.Width.Value = 200 sheet.TransformSection.Height.Value = 200 sheet.TransformSection.Angle.Value = 0 sheet.TransformSection.PinX.Value = 100 sheet.TransformSection.PinY.Value = 100 sheet.TransformSection.LocPinX.Formula = "Width*0.5" sheet.TransformSection.LocPinY.Formula = "Height*0.5" ' add a geometry Dim geometry1 As New NGeometrySection("Geometry1", "Geometry1") sheet.Sections.Add(geometry1) geometry1.AddMoveTo("0", "Height/2-Scratch.Y1") geometry1.AddLineTo("Width/2-Scratch.X1", "Geometry1.Y1") geometry1.AddLineTo("Geometry1.X2", "0") geometry1.AddLineTo("Geometry1.X2+2*Scratch.X1", "0") geometry1.AddLineTo("Geometry1.X4", "Geometry1.Y2") geometry1.AddLineTo("Width", "Geometry1.Y1") geometry1.AddLineTo("Geometry1.X6", "Geometry1.Y1+2*Scratch.Y1") geometry1.AddLineTo("Geometry1.X4", "Geometry1.Y7") geometry1.AddLineTo("Geometry1.X4", "Height") geometry1.AddLineTo("Geometry1.X2", "Geometry1.Y9") geometry1.AddLineTo("Geometry1.X2", "Geometry1.Y7") geometry1.AddLineTo("0", "Geometry1.Y7") geometry1.AddLineTo("Geometry1.X1", "Geometry1.Y1") ' add scratches sheet.ScratchSection = New NScratchSection sheet.ScratchSection.AddScratch( _ New NSingleFormulaCell("ABS(User.ControlX2-Width/2)"), _ New NSingleFormulaCell("ABS(User.ControlY1-Height/2)"), _ New NSingleFormulaCell(""), _ New NSingleFormulaCell(""), _ New NSingleFormulaCell(""), _ New NSingleFormulaCell("")) ' add users sheet.UserDefinedCellsSection = New NUserDefinedCellsSection sheet.UserDefinedCellsSection.AddUserCell("ControlX1", "MAX(0,MIN(Width/2,Controls.X1))") sheet.UserDefinedCellsSection.AddUserCell("ControlX2", "MAX(0,MIN(Width/2,Controls.X2))") sheet.UserDefinedCellsSection.AddUserCell("ControlY1", "MAX(0,MIN(Height/2,Controls.Y1))") sheet.UserDefinedCellsSection.AddUserCell("ControlY2", "MAX(0,MIN(Height/2,Controls.Y2))") ' add controls sheet.ControlsSection = New NControlsSection sheet.ControlsSection.AddControl("Width*0", "Height/2-10", True, ControlBehavior.Locked, ControlBehavior.OffsetFromCenter, "First control point") sheet.ControlsSection.AddControl("Width/2-10", "Height*0", True, ControlBehavior.OffsetFromCenter, ControlBehavior.Locked, "Second control point") shape.FillStyle = New NColorFillStyle(New NArgbColor(Color.Honeydew)) shape.StrokeStyle = New NStrokeStyle(1, New NArgbColor(Color.Black)) |