private void BackgroundFillStyleComboBox_SelectedIndexChanged_1(object sender, System.EventArgs e) { switch (BackgroundFillStyleComboBox.SelectedIndex) { case 0: // Solid color nChartControl1.BackgroundStyle.FillStyle = new NColorFillStyle(Color.BlanchedAlmond); break; case 1: // Gradient nChartControl1.BackgroundStyle.FillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant2, Color.AliceBlue, Color.BlanchedAlmond); break; case 2: // Image { NImageFillStyle imageFillStyle = new NImageFillStyle(NResourceHelper.BitmapFromResource(this.GetType(), "Back.png", "Nevron.Examples.Chart.WinForm.Resources")); imageFillStyle.TextureMappingStyle.MapLayout = MapLayout.Tiled; nChartControl1.BackgroundStyle.FillStyle = imageFillStyle; } break; case 3: // Pattern nChartControl1.BackgroundStyle.FillStyle = new NHatchFillStyle(HatchStyle.Divot, Color.BlueViolet, Color.Beige); break; case 4: // Advanced gradient nChartControl1.BackgroundStyle.FillStyle = new NAdvancedGradientFillStyle(AdvancedGradientScheme.Ocean3, 12); break; } nChartControl1.Refresh(); }
private void ChartControl_OnMouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (nChartControl1.Controller.ActiveTool != null) { return; } NHitTestResult result = nChartControl1.HitTest(e.X, e.Y); NWatermark watermark = result.Object as NWatermark; if (watermark == null || watermark.Tag == null) { if (SetWatermarkTransparency((byte)(TransparencyScrollBar.Value * 255 / 100))) { nChartControl1.Refresh(); } } else { NImageFillStyle imageFillStyle = (NImageFillStyle)watermark.FillStyle; if (imageFillStyle.Alpha != 255) { SetWatermarkTransparency((byte)(TransparencyScrollBar.Value * 255 / 100)); imageFillStyle.Alpha = 255; nChartControl1.Refresh(); } } }
private bool SetWatermarkTransparency(byte alpha) { bool alphaChanged = false; for (int i = 0; i < nChartControl1.Watermarks.Count; i++) { NWatermark watermark = (NWatermark)nChartControl1.Watermarks[i]; if (watermark.Tag != null) { NImageFillStyle imageFillStyle = watermark.FillStyle as NImageFillStyle; if (imageFillStyle != null) { if (imageFillStyle.Alpha != alpha) { imageFillStyle.Alpha = alpha; alphaChanged = true; } } } } return(alphaChanged); }
private void ChooseImageWalls_Click(object sender, System.EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { NImageFillStyle imageFillStyle = new NImageFillStyle(openFileDialog1.FileName); m_Chart.Wall(ChartWallType.Back).FillStyle = imageFillStyle; m_Chart.Wall(ChartWallType.Left).FillStyle = imageFillStyle; m_Chart.Wall(ChartWallType.Floor).FillStyle = imageFillStyle; nChartControl1.Refresh(); } }
public override void Initialize() { base.Initialize(); // load textures from resources Bitmap bmp0 = NResourceHelper.BitmapFromResource(this.GetType(), "Back.png", "Nevron.Examples.Chart.WinForm.Resources"); Bitmap bmp1 = NResourceHelper.BitmapFromResource(this.GetType(), "Leafs.png", "Nevron.Examples.Chart.WinForm.Resources"); Bitmap bmp2 = NResourceHelper.BitmapFromResource(this.GetType(), "Banner.png", "Nevron.Examples.Chart.WinForm.Resources"); NImageFillStyle imageFillStyle = new NImageFillStyle(bmp0); imageFillStyle.TextureMappingStyle.MapLayout = MapLayout.Tiled; nChartControl1.BackgroundStyle.FillStyle = imageFillStyle; // add label NLabel title = nChartControl1.Labels.AddHeader("Image Fill Style"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.TextStyle.FillStyle = new NColorFillStyle(GreyBlue); title.ContentAlignment = ContentAlignment.BottomCenter; title.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage)); // setup chart and axes m_Chart = nChartControl1.Charts[0]; m_Chart.Projection.SetPredefinedProjection(PredefinedProjection.Perspective); m_Chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.SoftTopLeft); m_Chart.Axis(StandardAxis.Depth).Visible = false; NLinearScaleConfigurator linearScale = (NLinearScaleConfigurator)m_Chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator; linearScale.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot; linearScale.MajorGridStyle.LineStyle.Color = Color.White; linearScale = new NLinearScaleConfigurator(); m_Chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = linearScale; linearScale.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot; linearScale.MajorGridStyle.LineStyle.Color = Color.White; linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true); // Setup walls Color c = Color.FromArgb(128, 128, 192); imageFillStyle = new NImageFillStyle(bmp1); imageFillStyle.TextureMappingStyle.MapLayout = MapLayout.Tiled; m_Chart.Wall(ChartWallType.Back).FillStyle = imageFillStyle; m_Chart.Wall(ChartWallType.Left).FillStyle = imageFillStyle; m_Chart.Wall(ChartWallType.Floor).FillStyle = imageFillStyle; // create bubble chart m_Bubble = (NBubbleSeries)m_Chart.Series.Add(SeriesType.Bubble); m_Bubble.DataLabelStyle.Visible = false; m_Bubble.Legend.Mode = SeriesLegendMode.DataPoints; m_Bubble.BubbleShape = PointShape.Ellipse; m_Bubble.UseXValues = true; m_Bubble.InflateMargins = true; m_Bubble.BorderStyle.Width = new NLength(1, NGraphicsUnit.Pixel); m_Bubble.FillStyle = new NImageFillStyle(bmp2); GenerateData(); }
public override void Initialize() { base.Initialize(); // Enable GPU acceleration nChartControl1.Settings.RenderSurface = RenderSurface.Window; nChartControl1.Controller.Tools.Add(new NPanelSelectorTool()); nChartControl1.Controller.Tools.Add(new NTrackballTool()); // set a chart title NLabel title = new NLabel("Surface With Texture"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.TextStyle.FillStyle = new NColorFillStyle(GreyBlue); // no legends nChartControl1.Legends.Clear(); // configure the chart NChart chart = nChartControl1.Charts[0]; chart.Enable3D = true; chart.Width = 60.0f; chart.Depth = 60.0f; chart.Height = 15.0f; chart.BoundsMode = BoundsMode.Fit; chart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveTilted); chart.Projection.Elevation = 45; chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.ShinyTopLeft); // setup Y axis NLinearScaleConfigurator scaleY = new NLinearScaleConfigurator(); scaleY.RoundToTickMax = false; scaleY.RoundToTickMin = false; scaleY.MinTickDistance = new NLength(10, NGraphicsUnit.Point); scaleY.MajorGridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Left, ChartWallType.Back }; scaleY.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot; chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator = scaleY; // setup X axis NLinearScaleConfigurator scaleX = new NLinearScaleConfigurator(); scaleX.RoundToTickMax = false; scaleX.RoundToTickMin = false; scaleX.MajorGridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Floor, ChartWallType.Back }; scaleX.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot; chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX; // setup Z axis NLinearScaleConfigurator scaleZ = new NLinearScaleConfigurator(); scaleZ.RoundToTickMax = false; scaleZ.RoundToTickMin = false; scaleZ.MajorGridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Floor, ChartWallType.Left }; scaleZ.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot; chart.Axis(StandardAxis.Depth).ScaleConfigurator = scaleZ; // add the surface series NGridSurfaceSeries surface = (NGridSurfaceSeries)chart.Series.Add(SeriesType.GridSurface); surface.Name = "Surface"; surface.FrameMode = SurfaceFrameMode.None; surface.FillMode = SurfaceFillMode.Uniform; surface.Data.SetGridSize(60, 60); FillData(); Bitmap bitmap = NResourceHelper.BitmapFromResource(this.GetType(), "Marble.jpg", "Nevron.Examples.Chart.WinForm.Resources"); NImageFillStyle imageFillStyle = new NImageFillStyle(bitmap); imageFillStyle.TextureMappingStyle.MapLayout = MapLayout.Tiled; imageFillStyle.TextureMappingStyle.HorizontalScale = 0.1f; imageFillStyle.TextureMappingStyle.VerticalScale = 0.1f; imageFillStyle.MaterialStyle.Diffuse = Color.FromArgb(204, 204, 0); imageFillStyle.MaterialStyle.Ambient = Color.FromArgb(51, 102, 153); imageFillStyle.MaterialStyle.Specular = Color.DarkGray; surface.FillStyle = imageFillStyle; // apply layout ConfigureStandardLayout(chart, title, null); // form controls smoothShadingCheck.Checked = true; texturePlaneCombo.SelectedIndex = 0; }
public override void Initialize() { base.Initialize(); nChartControl1.Controller.Tools.Add(new NPanelSelectorTool()); nChartControl1.Controller.Tools.Add(new NTrackballTool()); // set a chart title NLabel title = nChartControl1.Labels.AddHeader("Shape Series used to display a house"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.TextStyle.FillStyle = new NColorFillStyle(GreyBlue); // setup chart m_Chart = nChartControl1.Charts[0]; m_Chart.Enable3D = true; m_Chart.Depth = 55.0f; m_Chart.Width = 55.0f; m_Chart.Height = 55.0f; m_Chart.Projection.Type = ProjectionType.Perspective; m_Chart.Projection.Rotation = -19.0f; m_Chart.Projection.Elevation = 20.0f; // configure axes NLinearScaleConfigurator linearScale = new NLinearScaleConfigurator(); m_Chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = linearScale; linearScale.MajorTickMode = MajorTickMode.AutoMaxCount; linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true); linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); linearScale = new NLinearScaleConfigurator(); m_Chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator = linearScale; linearScale.MajorTickMode = MajorTickMode.AutoMaxCount; linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true); linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Left, true); linearScale = new NLinearScaleConfigurator(); m_Chart.Axis(StandardAxis.Depth).ScaleConfigurator = linearScale; linearScale.MajorTickMode = MajorTickMode.AutoMaxCount; linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Left, true); NLegend legend = (NLegend)nChartControl1.Legends[0]; legend.Data.MarkSize = new NSizeL(20, 20); // create the door NShapeSeries shape = (NShapeSeries)m_Chart.Series.Add(SeriesType.Shape); shape.Name = "door"; shape.DataLabelStyle.Visible = false; shape.UseXValues = true; shape.UseZValues = true; shape.Shape = BarShape.Bar; shape.AddDataPoint(new NShapeDataPoint(-0.5, -0.25, -1.0, 0.5, 1.5, 0.02)); NImageFillStyle doorFS = new NImageFillStyle(NResourceHelper.BitmapFromResource(this.GetType(), "Door.jpg", "Nevron.Examples.Chart.WinForm.Resources")); shape.FillStyle = doorFS; // create the window shape = (NShapeSeries)m_Chart.Series.Add(SeriesType.Shape); shape.Name = "window"; shape.DataLabelStyle.Visible = false; shape.UseXValues = true; shape.UseZValues = true; shape.Shape = BarShape.Bar; shape.AddDataPoint(new NShapeDataPoint(0.4, 0.0, -1.0, 0.75, 1.0, 0.02)); NImageFillStyle windowFS = new NImageFillStyle(NResourceHelper.BitmapFromResource(this.GetType(), "Window.jpg", "Nevron.Examples.Chart.WinForm.Resources")); shape.FillStyle = windowFS; // create the house shape = (NShapeSeries)m_Chart.Series.Add(SeriesType.Shape); shape.Name = "house"; shape.DataLabelStyle.Visible = false; shape.UseXValues = true; shape.UseZValues = true; shape.Shape = BarShape.Bar; shape.AddDataPoint(new NShapeDataPoint(0.0, 0.0, 0.0, 2.0, 2.0, 2.0)); shape.FillStyle = new NColorFillStyle(Color.White); NImageFillStyle houseFS = new NImageFillStyle(NResourceHelper.BitmapFromResource(this.GetType(), "Cobblestone.jpg", "Nevron.Examples.Chart.WinForm.Resources")); houseFS.TextureMappingStyle.MapLayout = MapLayout.Tiled; houseFS.TextureMappingStyle.HorizontalScale = 0.1f; houseFS.TextureMappingStyle.VerticalScale = 0.1f; shape.FillStyle = houseFS; // create the roof shape = (NShapeSeries)m_Chart.Series.Add(SeriesType.Shape); shape.Name = "roof"; shape.DataLabelStyle.Visible = false; shape.UseXValues = true; shape.UseZValues = true; shape.Shape = BarShape.Pyramid; shape.AddDataPoint(new NShapeDataPoint(0.0, 1.5, 0.0, 2.4, 1.0, 2.4)); NImageFillStyle roofFS = new NImageFillStyle(NResourceHelper.BitmapFromResource(this.GetType(), "Rooftile.jpg", "Nevron.Examples.Chart.WinForm.Resources")); roofFS.TextureMappingStyle.MapLayout = MapLayout.Tiled; roofFS.TextureMappingStyle.HorizontalScale = 0.2f; roofFS.TextureMappingStyle.VerticalScale = 0.2f; shape.FillStyle = roofFS; // create the chimney shape = (NShapeSeries)m_Chart.Series.Add(SeriesType.Shape); shape.Name = "chimney"; shape.DataLabelStyle.Visible = false; shape.UseXValues = true; shape.UseZValues = true; shape.Shape = BarShape.Cylinder; shape.AddDataPoint(new NShapeDataPoint(0.75, 1.5, 0.0, 0.2, 1.0, 0.2)); NImageFillStyle chimneyFS = new NImageFillStyle(NResourceHelper.BitmapFromResource(this.GetType(), "Bricks.jpg", "Nevron.Examples.Chart.WinForm.Resources")); chimneyFS.TextureMappingStyle.MapLayout = MapLayout.Tiled; chimneyFS.TextureMappingStyle.HorizontalScale = 0.1f; chimneyFS.TextureMappingStyle.VerticalScale = 0.1f; shape.FillStyle = chimneyFS; // apply layout ConfigureStandardLayout(m_Chart, title, nChartControl1.Legends[0]); }
protected NCompositeShape CreateOrgChartShape(NPersonalInfo info) { NRectangleF bounds = info.Bounds; float bottomPortAlignment = info.BottomPortAlignment; Bitmap photo = new Bitmap(this.MapPathSecure(info.Picture)); // compose a new graph vertex from a frame and an image NRectanglePath frame = new NRectanglePath(bounds); NRectanglePath image = new NRectanglePath(new NPointF(bounds.X + 5, bounds.Y + 5), new NSizeF(photo.Size)); NImageFillStyle imgageFillStyle = new NImageFillStyle(photo, 0xff); NStyle.SetFillStyle(image, imgageFillStyle); NCompositeShape shape = new NCompositeShape(); shape.Primitives.AddChild(frame); shape.Primitives.AddChild(image); shape.UpdateModelBounds(); Document.ActiveLayer.AddChild(shape); // set the vertex fill style NColorFillStyle fillStyle = null; switch (info.Level) { case 0: fillStyle = new NColorFillStyle(Color.FromArgb(241, 100, 34)); break; case 1: fillStyle = new NColorFillStyle(Color.FromArgb(249, 167, 26)); break; case 2: fillStyle = new NColorFillStyle(Color.FromArgb(255, 247, 151)); break; } fillStyle.ImageFiltersStyle.Filters.Add(new NLightingImageFilter()); shape.Style.FillStyle = fillStyle; NInteractivityStyle interactivityStyle = new NInteractivityStyle(); interactivityStyle.Tooltip.Text = "Click to show " + info.Name + " personal information"; interactivityStyle.UrlLink.Url = "../Examples/WebControl/GettingStarted/NPersonalInfoPage.aspx?" + info.Id.ToString(); shape.Style.InteractivityStyle = interactivityStyle; // add a new label for the person name NRotatedBoundsLabel nameLabel = new NRotatedBoundsLabel(info.Name, shape.UniqueId, new Nevron.Diagram.NMargins(40, 1, 50, 1)); shape.Labels.AddChild(nameLabel); NStyle.SetTextStyle(nameLabel, nameLabel.ComposeTextStyle().Clone() as NTextStyle); nameLabel.Style.TextStyle.StringFormatStyle.HorzAlign = HorzAlign.Right; nameLabel.Style.TextStyle.StringFormatStyle.VertAlign = VertAlign.Top; // configure default label (used for the person position) NRotatedBoundsLabel positionLabel = shape.Labels.DefaultLabel as NRotatedBoundsLabel; NStyle.SetTextStyle(positionLabel, positionLabel.ComposeTextStyle().Clone() as NTextStyle); positionLabel.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial", 10, FontStyle.Bold)); positionLabel.Style.TextStyle.StringFormatStyle.HorzAlign = HorzAlign.Right; positionLabel.Style.TextStyle.StringFormatStyle.VertAlign = VertAlign.Bottom; positionLabel.Margins = new Nevron.Diagram.NMargins(40, 5, 1, 50); positionLabel.Text = info.Position; // create the optional ports of the shape shape.CreateShapeElements(ShapeElementsMask.Ports); // add rotated bounds ports NPort leftPort = new NRotatedBoundsPort(shape.UniqueId, new NContentAlignment(ContentAlignment.MiddleLeft)); leftPort.Name = "Left"; shape.Ports.AddChild(leftPort); NPort rightPort = new NRotatedBoundsPort(shape.UniqueId, new NContentAlignment(ContentAlignment.MiddleRight)); rightPort.Name = "Right"; shape.Ports.AddChild(rightPort); NPort topPort = new NRotatedBoundsPort(shape.UniqueId, new NContentAlignment(ContentAlignment.TopCenter)); topPort.Name = "Top"; shape.Ports.AddChild(topPort); NRotatedBoundsPort bottomPort = new NRotatedBoundsPort(shape.UniqueId, new NContentAlignment(bottomPortAlignment, 50)); bottomPort.Name = "Bottom"; shape.Ports.AddChild(bottomPort); return(shape); }
void InitToolbar() { if (nDrawingViewToolbar.RequiresInitialization) { ActiveCommand = toolbarButtons[0].CommandName; // begin view init nDrawingViewToolbar.ViewLayout = CanvasLayout.Normal; nDrawingViewToolbar.DocumentPadding = new Nevron.Diagram.NMargins(0); // init document nDrawingViewToolbar.Document.BeginInit(); nDrawingViewToolbar.Document.AutoBoundsPadding = new Nevron.Diagram.NMargins(4); nDrawingViewToolbar.Document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; nDrawingViewToolbar.Document.GraphicsSettings.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; nDrawingViewToolbar.Document.GraphicsSettings.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; // set up visual formatting nDrawingViewToolbar.Document.Style.FillStyle = new NColorFillStyle(Color.White); nDrawingViewToolbar.Document.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial Narrow", 8)); nDrawingViewToolbar.Document.BackgroundStyle.FrameStyle.Visible = false; // set up the shape factories NBasicShapesFactory buttonFactory = new NBasicShapesFactory(nDrawingViewToolbar.Document); buttonFactory.DefaultSize = new NSizeF(24, 24); NBrainstormingShapesFactory iconFactory = new NBrainstormingShapesFactory(nDrawingViewToolbar.Document); iconFactory.DefaultSize = new NSizeF(16, 16); // create a batch layout, which will align shapes NBatchLayout batchLayout = new NBatchLayout(nDrawingViewToolbar.Document); // create buttons int count = toolbarButtons.Length; for (int i = 0; i < count; i++) { ToolbarButton btn = toolbarButtons[i]; bool isActive = (this.ActiveCommand == btn.CommandName); NShape buttonShape = buttonFactory.CreateShape(BasicShapes.RoundedRectangle); // create the button shape group NGroup g = new NGroup(); NBatchGroup bgroup = new NBatchGroup(nDrawingViewToolbar.Document); NNodeList shapes = new NNodeList(); if (btn.IsSeparator) { buttonShape.Width /= 2; buttonShape.Style.StrokeStyle = new NStrokeStyle(Color.White); shapes.Add(buttonShape); } else if (!btn.IsColorSelector) { shapes.Add(buttonShape); } else { buttonShape.Style.FillStyle = new NColorFillStyle(btn.Color); shapes.Add(buttonShape); } NRectanglePath imagePath = new NRectanglePath(0f, 0f, btn.IconSize.Width, btn.IconSize.Height); NImageFillStyle fs1 = new NImageFillStyle(this.MapPathSecure(@"..\..\..\Images\FlowChartBuilder\" + btn.IconFile)); NStyle.SetFillStyle(imagePath, fs1); NStyle.SetStrokeStyle(imagePath, new NStrokeStyle(0, Color.White)); NCompositeShape imageShape = new NCompositeShape(); imageShape.Primitives.AddChild(imagePath); imageShape.UpdateModelBounds(); shapes.Add(imageShape); NShape coverShape = buttonFactory.CreateShape(BasicShapes.RoundedRectangle); coverShape.Width = buttonShape.Width; coverShape.Name = "coverShape"; shapes.Add(coverShape); if (!isActive && !btn.IsClientSide && !btn.IsSeparator) { if (btn.IsColorSelector) { coverShape.Style.FillStyle = new NColorFillStyle(Color.FromArgb(180, Color.White)); } else { coverShape.Style.FillStyle = new NColorFillStyle(Color.FromArgb(160, Color.White)); } coverShape.Style.StrokeStyle = new NStrokeStyle(Color.FromArgb(160, Color.White)); } else { coverShape.Style.FillStyle = new NColorFillStyle(Color.FromArgb(0, Color.White)); coverShape.Style.StrokeStyle = new NStrokeStyle(Color.FromArgb(0, Color.White)); if (!btn.IsSeparator) { coverShape.Style.ShadowStyle = new NShadowStyle(ShadowType.GaussianBlur, Color.FromArgb(70, Color.Black), new NPointL(1, 0)); } } // perform layout batchLayout.Build(shapes); batchLayout.AlignVertically(buttonShape, VertAlign.Center, false); batchLayout.AlignHorizontally(buttonShape, HorzAlign.Center, false); // group shapes bgroup.Build(shapes); bgroup.Group(null, false, out g); // enable interactivity if (!btn.IsSeparator) { g.Style.InteractivityStyle = new NInteractivityStyle(true, btn.CommandName, btn.Title, CursorType.Hand); } // set the command of the button g.Tag = btn.CommandName; nDrawingViewToolbar.Document.ActiveLayer.AddChild(g); } // layout the shapes in the active layer using a table layout NTableLayout layout = new NTableLayout(); // setup the table layout layout.Direction = LayoutDirection.LeftToRight; layout.ConstrainMode = CellConstrainMode.Ordinal; layout.MaxOrdinal = toolbarButtons.Length; layout.HorizontalSpacing = 7; // create a layout context NLayoutContext layoutContext = new NLayoutContext(); layoutContext.GraphAdapter = new NShapeGraphAdapter(); layoutContext.BodyAdapter = new NShapeBodyAdapter(nDrawingViewToolbar.Document); layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(nDrawingViewToolbar.Document); // layout the shapes layout.Layout(nDrawingViewToolbar.Document.ActiveLayer.Children(null), layoutContext); nDrawingViewToolbar.Document.EndInit(); } }
NDrawingDocument CreateDocument(int bookId) { NDrawingDocument document = new NDrawingDocument(); // setup the document document.AutoBoundsPadding = new Nevron.Diagram.NMargins(0f, 7f, 7f, 7f); document.Style.FillStyle = new NColorFillStyle(Color.White); document.Style.TextStyle.FillStyle = new NColorFillStyle(Color.DarkGray); document.Style.TextStyle.StringFormatStyle.HorzAlign = HorzAlign.Left; document.Style.StrokeStyle = new NStrokeStyle(0, Color.White); NStandardFrameStyle frame = document.BackgroundStyle.FrameStyle as NStandardFrameStyle; frame.InnerBorderColor = Color.Gray; document.MeasurementUnit = NGraphicsUnit.Pixel; // set up the shape factories NBasicShapesFactory bookItemsFactory = new NBasicShapesFactory(document); bookItemsFactory.DefaultSize = new NSizeF(320, 200); NCustomToolsData.NBookEntry[] books = NCustomToolsData.CreateBooks(); NCustomToolsData.NBookEntry book = null; int length = books.Length; for (int i = 0; i < length; i++) { if (books[i].Id == bookId) { book = books[i]; break; } } if (bookId == -1 || book == null) { document.Style.StrokeStyle = new NStrokeStyle(1, Color.Red); document.ActiveLayer.AddChild(bookItemsFactory.CreateShape(BasicShapes.Pentagram)); document.SizeToContent(); return(document); } // create a table layout, which will align te thumbnail and the text lines // in two columns NTableLayout mainLayout = new NTableLayout(); mainLayout.Direction = LayoutDirection.LeftToRight; mainLayout.ConstrainMode = CellConstrainMode.Ordinal; mainLayout.MaxOrdinal = 2; mainLayout.VerticalContentPlacement = ContentPlacement.Near; // create a stack layout, which will align the text lines in rows NStackLayout textLayout = new NStackLayout(); textLayout.Direction = LayoutDirection.TopToBottom; textLayout.HorizontalContentPlacement = ContentPlacement.Near; textLayout.VerticalSpacing = 13; // create a stack layout, which will align the stars in 5 columns NStackLayout starsLayout = new NStackLayout(); starsLayout.Direction = LayoutDirection.LeftToRight; starsLayout.VerticalContentPlacement = ContentPlacement.Center; starsLayout.HorizontalSpacing = 1; NLayoutContext layoutContext = new NLayoutContext(); layoutContext.GraphAdapter = new NShapeGraphAdapter(); layoutContext.BodyAdapter = new NShapeBodyAdapter(document); layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(document); // create the shapes for the book image and text lines NShape bookImageShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle); bookImageShape.Width = 240f; bookImageShape.Height = 240f; NImageFillStyle fs1 = new NImageFillStyle(HttpContext.Current.Server.MapPath(@"~\Images\CustomTools\" + book.ImageFile)); fs1.TextureMappingStyle.MapLayout = MapLayout.Centered; NStyle.SetFillStyle(bookImageShape, fs1); NShape bookTitleShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle); bookTitleShape.Text = book.Title; bookTitleShape.Width = 160f; bookTitleShape.Height = 32f; NShape bookAuthorShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle); bookAuthorShape.Text = "by " + book.Author; bookAuthorShape.Width = 160f; bookAuthorShape.Height = 32f; NShape bookPriceShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle); bookPriceShape.Text = "Price: $" + book.Price.ToString(); bookPriceShape.Width = 160f; bookPriceShape.Height = 32f; // create the star shapes NNodeList starShapes = new NNodeList(); for (int i = 0; i < 5; i++) { NShape star = bookItemsFactory.CreateShape(BasicShapes.Pentagram); star.Width = 10f; star.Height = 10f; if (i < book.Rating) { star.Style.FillStyle = new NColorFillStyle(Color.Orange); } else { star.Style.FillStyle = new NColorFillStyle(Color.LightGray); } starShapes.Add(star); } // prepare to layout NBatchGroup bgroup = new NBatchGroup(document); // create the stars group NGroup starsGroup = new NGroup(); // group the star shapes bgroup.Build(starShapes); bgroup.Group(null, false, out starsGroup); // collect the text shapes NNodeList textShapes = new NNodeList(); textShapes.Add(bookTitleShape); textShapes.Add(bookAuthorShape); textShapes.Add(bookPriceShape); textShapes.Add(starsGroup); // create the text group NGroup textGroup = new NGroup(); // group the text shapes bgroup.Build(textShapes); bgroup.Group(null, false, out textGroup); // collect the main layout shapes NNodeList mainElements = new NNodeList(); mainElements.Add(bookImageShape); mainElements.Add(textGroup); // create the main group NGroup mainGroup = new NGroup(); // group the main elements bgroup.Build(mainElements); bgroup.Group(null, false, out mainGroup); document.ActiveLayer.AddChild(mainGroup); // size all text shapes to text bookTitleShape.SizeToText(new NMarginsF(6f, 0f, 6f, 0f)); bookAuthorShape.SizeToText(new NMarginsF(6f, 0f, 6f, 0f)); bookPriceShape.SizeToText(new NMarginsF(6f, 0f, 6f, 0f)); // layout the star shapes starsLayout.Layout(starShapes, layoutContext); starsGroup.UpdateModelBounds(); // perform layout on the text textLayout.Layout(textShapes, layoutContext); textGroup.UpdateModelBounds(); // layout all elements mainLayout.Layout(mainElements, layoutContext); mainGroup.UpdateModelBounds(); // correct the text left padding bookTitleShape.Location = new NPointF(bookTitleShape.Location.X - 6f, bookTitleShape.Location.Y); bookAuthorShape.Location = new NPointF(bookAuthorShape.Location.X - 6f, bookAuthorShape.Location.Y); bookPriceShape.Location = new NPointF(bookPriceShape.Location.X - 6f, bookPriceShape.Location.Y); document.SizeToContent(); return(document); }
void InitDocument() { // set up visual formatting NDrawingView1.Document.Style.FillStyle = new NColorFillStyle(Color.White); NDrawingView1.Document.BackgroundStyle.FrameStyle.Visible = false; NCustomToolsData.NBookEntry[] books = NCustomToolsData.CreateBooks(); // set up the shape factories NBasicShapesFactory bookItemsFactory = new NBasicShapesFactory(NDrawingView1.Document); bookItemsFactory.DefaultSize = new NSizeF(150, 100); // create a table layout, which will align te thumbnail and the text within a group NTableLayout bookThumbLayout = new NTableLayout(); bookThumbLayout.Direction = LayoutDirection.LeftToRight; bookThumbLayout.ConstrainMode = CellConstrainMode.Ordinal; bookThumbLayout.MaxOrdinal = 1; // create a table layout, which will align all books in a grid NTableLayout tableLayout = new NTableLayout(); tableLayout.Direction = LayoutDirection.LeftToRight; tableLayout.ConstrainMode = CellConstrainMode.Ordinal; tableLayout.MaxOrdinal = 4; tableLayout.HorizontalSpacing = 7; tableLayout.VerticalSpacing = 7; NLayoutContext layoutContext = new NLayoutContext(); layoutContext.GraphAdapter = new NShapeGraphAdapter(); layoutContext.BodyAdapter = new NShapeBodyAdapter(NDrawingView1.Document); layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(NDrawingView1.Document); int length = books.Length; for (int i = 0; i < length; i++) { NCustomToolsData.NBookEntry book = books[i]; NShape bookThumbnailShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle); NImageFillStyle fs1 = new NImageFillStyle(this.MapPathSecure(@"..\..\..\..\Images\CustomTools\" + book.ThumbnailFile)); fs1.TextureMappingStyle.MapLayout = MapLayout.Centered; NStyle.SetFillStyle(bookThumbnailShape, fs1); NStyle.SetStrokeStyle(bookThumbnailShape, new NStrokeStyle(0, Color.White)); NShape bookTextShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle); NStyle.SetStrokeStyle(bookTextShape, new NStrokeStyle(0, Color.White)); bookTextShape.Text = book.Title; bookTextShape.Height = 50f; bookThumbnailShape.Style.InteractivityStyle = new NInteractivityStyle(true, book.Id.ToString(), null, CursorType.Hand); bookTextShape.Style.InteractivityStyle = new NInteractivityStyle(true, book.Id.ToString(), null, CursorType.Hand); // create the book tumbnail group NGroup g = new NGroup(); NBatchGroup bgroup = new NBatchGroup(NDrawingView1.Document); NNodeList shapes = new NNodeList(); shapes.Add(bookThumbnailShape); shapes.Add(bookTextShape); // perform layout bookThumbLayout.Layout(shapes, layoutContext); // group shapes bgroup.Build(shapes); bgroup.Group(null, false, out g); NDrawingView1.Document.ActiveLayer.AddChild(g); } // layout the books tableLayout.Layout(NDrawingView1.Document.ActiveLayer.Children(null), layoutContext); }
public override void Initialize() { base.Initialize(); nChartControl1.Settings.ShapeRenderingMode = ShapeRenderingMode.None; nChartControl1.Controller.Tools.Add(new NPanelSelectorTool()); nChartControl1.Controller.Tools.Add(new NTrackballTool()); // set a chart title NLabel title = nChartControl1.Labels.AddHeader("Mesh Surface With Texture"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.TextStyle.FillStyle = new NColorFillStyle(GreyBlue); title.ContentAlignment = ContentAlignment.BottomCenter; title.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage)); // no legend nChartControl1.Legends.Clear(); // configure the chart NChart chart = nChartControl1.Charts[0]; chart.Enable3D = true; chart.Width = 60.0f; chart.Depth = 60.0f; chart.Height = 25.0f; chart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveTilted); // setup axes NLinearScaleConfigurator linearScale = new NLinearScaleConfigurator(); linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true); linearScale.RoundToTickMax = false; linearScale.RoundToTickMin = false; chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = linearScale; linearScale = new NLinearScaleConfigurator(); linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Left, true); linearScale.RoundToTickMax = false; linearScale.RoundToTickMin = false; chart.Axis(StandardAxis.Depth).ScaleConfigurator = linearScale; // setup surface NMeshSurfaceSeries surface = (NMeshSurfaceSeries)chart.Series.Add(SeriesType.MeshSurface); surface.Name = "Surface"; surface.FrameMode = SurfaceFrameMode.None; surface.FillMode = SurfaceFillMode.Uniform; surface.Data.SetGridSize(50, 50); FillData(surface); NImageFillStyle imageFillStyle = new NImageFillStyle(NResourceHelper.BitmapFromResource(this.GetType(), "Marble.jpg", "Nevron.Examples.Chart.WinForm.Resources")); imageFillStyle.TextureMappingStyle.MapLayout = MapLayout.Tiled; imageFillStyle.TextureMappingStyle.HorizontalScale = 0.1f; imageFillStyle.TextureMappingStyle.VerticalScale = 0.1f; surface.FillStyle = imageFillStyle; // apply layout ConfigureStandardLayout(chart, title, null); // form controls smoothShadingCheck.Checked = true; }