Background Pages Example for Blazor

Nevron NOV Diagram for Blazor ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All Blazor Diagram examples are also available as a stand-alone Visual Studio solution in C#, which you can download from the links below.

Background Pages Example for Blazor Description

This example demonstrates background pages. Background pages serve as a backdrop for other pages. In this example, there are 2 two foreground pages that use a single background page (animated bubbles).

Whether a page is a background page or not depends on the PageType property. By default, pages are of the Foreground type.

Background pages can be mapped inside the foreground page like ordinary vector textures (stretched, fitted, tiled, etc.). Background pages are also automatically excluded from presentations.

In the Drawing Explorer, background and foreground pages are automatically separated into "Foreground Pages" and "Background Pages" folders.


Background Pages Example

C# Background Pages Example Code for Nevron Diagram for Blazor
Language: C#

using Nevron.Nov;
using Nevron.Nov.DataStructures;
using Nevron.Nov.Diagram;
using Nevron.Nov.Diagram.Editors;
using Nevron.Nov.Diagram.Shapes;
using Nevron.Nov.Diagram.UI;
using Nevron.Nov.Dom;
using Nevron.Nov.Editors;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Text;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;

namespace NovWinFormsProject
{
	public partial class Form1 : Form
	{
		#region Constructors

		public Form1()
		{
			InitializeComponent();

			// Set form title
			Text = "NOV WinForms - NBackgroundPagesExample";

			// Create the NOV example and its controls
			NWidget exampleContent = CreateExampleContent();
			NWidget exampleControls = CreateExampleControls();
			if (exampleControls != null)
			{
				exampleControls.PreferredWidth = 300;
			}

			// Place the example and its controls in a pair box
			NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
			pairBox.FillMode = ENStackFillMode.First;
			pairBox.FitMode = ENStackFitMode.First;
			pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);

			// Host the example in the form
			NNovWidgetHost host = new NNovWidgetHost(pairBox);
			host.Dock = DockStyle.Fill;
			Controls.Add(host);
		}

		#endregion

        #region Example

        public NWidget CreateExampleContent()
        {
            // Create a simple drawing
            NDrawingViewWithRibbon drawingViewWithRibbon = new NDrawingViewWithRibbon();
            m_DrawingView = drawingViewWithRibbon.View;

            m_DrawingView.Document.HistoryService.Pause();
            try
            {
                InitDiagram(m_DrawingView.Document);
            }
            finally
            {
                m_DrawingView.Document.HistoryService.Resume();
            }

            return drawingViewWithRibbon;
        }
        public NWidget CreateExampleControls()
        {
            NStackPanel stackPanel = new NStackPanel();
            stackPanel.FillMode = ENStackFillMode.Last;
            stackPanel.FitMode = ENStackFitMode.Last;

            NDrawingExplorer drawingExplorer = new NDrawingExplorer();
            drawingExplorer.DrawingView = m_DrawingView;
            stackPanel.Add(drawingExplorer);

            return stackPanel;
        }
        public string GetExampleDescription()
        {
            return @"

This example demonstrates background pages. Background pages serve as a backdrop for other pages. In this example, there are 2 two foreground pages that use a single background page (animated bubbles).

Whether a page is a background page or not depends on the PageType property. By default, pages are of the Foreground type.

Background pages can be mapped inside the foreground page like ordinary vector textures (stretched, fitted, tiled, etc.). Background pages are also automatically excluded from presentations.

In the Drawing Explorer, background and foreground pages are automatically separated into ""Foreground Pages"" and ""Background Pages"" folders.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Page Types", "https://www.nevron.com/docs/openvision/diagram-page-types.html"), ("Pages", "https://www.nevron.com/docs/openvision/diagram-pages.html"), }; } private void InitDiagram(NDrawingDocument drawingDocument) { NDrawing drawing = drawingDocument.Content; drawing.Pages.Clear(); NColor[] colors = new NColor[] { new NColor(222, 221, 237), new NColor(240, 234, 246), new NColor(216, 215, 234), new NColor(170, 168, 209) }; // create a page for background NPage backgroundPage = new NPage(); backgroundPage.Title = "Background Page"; backgroundPage.PageType = ENPageType.Background; Random rnd = new Random(); // create bubbles in this page NBasicShapeFactory factory = new NBasicShapeFactory(); for (int i = 0; i < 30; i++) { NShape shape = factory.CreateShape(ENBasicShape.Circle); // select random x, y, size and color double x = (double)rnd.Next((int)backgroundPage.Width); double y = (double)rnd.Next((int)backgroundPage.Height); double size = (double)rnd.Next(200); int colorIndex = (byte)rnd.Next(colors.Length); backgroundPage.Items.Add(shape); shape.SetBounds(NRectangle.FromCenterAndSize(new NPoint(x,y), size, size)); shape.Geometry.Fill = new NColorFill(colors[colorIndex]); shape.Geometry.Stroke = null; } drawing.Pages.Add(backgroundPage); // create a foreground page NPage foregroundPage1 = new NPage(); foregroundPage1.Title = "Foreground Page 1"; foregroundPage1.BackgroundPage = backgroundPage; drawing.Pages.Insert(0, foregroundPage1); CreateTitle("Foreground Page 1", foregroundPage1); NPage foregroundPage2 = new NPage(); foregroundPage2.Title = "Foreground Page 2"; foregroundPage2.BackgroundPage = backgroundPage; drawing.Pages.Insert(1, foregroundPage2); CreateTitle("Foreground Page 2", foregroundPage2); // get shapes and assign a mover to each of them them NList shapes = backgroundPage.GetShapes(false); for (int i = 0; i < shapes.Count; i++) { NShape shape = shapes[i]; // create a shape mover that will move the shapes in random directions inside the page float vx = (float)(rnd.NextDouble() * 4 + 1) * (rnd.Next(2) == 0 ? -1 : 1); float vy = (float)(rnd.NextDouble() * 4 + 1) * (rnd.Next(2) == 0 ? -1 : 1); NShapeMover shapeMover = new NShapeMover(vx, vy); shape.Tag = shapeMover; } // create a timer to move the shapes m_MoveTimer = new NTimer(); m_MoveTimer.Interval = 100; m_MoveTimer.Start(); m_MoveTimer.Tick += () => { shapes = backgroundPage.GetShapes(false); for (int i = 0; i < shapes.Count; i++) { NShape shape = shapes[i]; NShapeMover shapeMover = (shape.Tag as NShapeMover); if (shapeMover != null) { shapeMover.MoveShape(shape, backgroundPage); } } }; } private void CreateTitle(string title, NPage page) { // create title NShape titleShape = new NShape(); titleShape.Width = page.Width; titleShape.Height = 75; titleShape.PinX = page.X + page.Width / 2; titleShape.PinY = page.Y + titleShape.Height / 2; titleShape.Text = title; titleShape.TextBlock.FontName = "Arial"; titleShape.TextBlock.FontSize = 40; titleShape.TextBlock.FontStyle = ENFontStyle.Bold; titleShape.TextBlock.Fill = new NColorFill(new NColor(68, 90, 108)); titleShape.TextBlock.Shadow = new NShadow(); page.Items.AddChild(titleShape); } protected void OnUnregistered() { base.OnUnregistered(); if (m_MoveTimer != null) { m_MoveTimer.Stop(); } } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields private NDrawingView m_DrawingView; private NTimer m_MoveTimer; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Background Pages Example for Blazor Solution

Related Documentation Links