Keyboard Events Example for Blazor

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

Keyboard Events Example for Blazor Description

Demonstrates the keyboard support in NOV. Click on the canvas and start pressing the keyboard keys to see the keyboard events that NOV sends to the application. Keyboard support is available to most desktop enviroments.


Keyboard Events Example

C# Keyboard Events Example Code for Nevron UserInterface for Blazor
Language: C#

using Nevron.Nov;
using Nevron.Nov.DataStructures;
using Nevron.Nov.Dom;
using Nevron.Nov.Editors;
using Nevron.Nov.Globalization;
using Nevron.Nov.Graphics;
using Nevron.Nov.IO;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.IO;
using System.Windows.Forms;

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

		public Form1()
		{
			InitializeComponent();

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

			// 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()
        {
            m_Canvas = new NCanvas();
            m_Canvas.PrePaint += OnCanvasPrePaint;

            // subscribe for keyboard events
            m_Canvas.KeyDown += OnCanvasKeyDown;
            m_Canvas.KeyUp += OnCanvasKeyUp;
            m_Canvas.InputChar += OnCanvasInputChar;
            m_Canvas.GotFocus += OnCanvasGotFocus;
            m_Canvas.LostFocus += OnCanvasLostFocus;

            // subscribe for mouse events
            m_Canvas.MouseDown += OnCanvasMouseDown;

            return m_Canvas;
        }

        public NWidget CreateExampleControls()
        {
            NStackPanel stack = new NStackPanel();
            stack.FitMode = ENStackFitMode.Last;
            stack.FillMode = ENStackFillMode.Last;

            // handle key up
            m_HandleKeyDown = new NCheckBox("Handle Key Down");
            stack.Add(m_HandleKeyDown);

            // handle key up
            m_HandleKeyUp = new NCheckBox("Handle Key Up");
            stack.Add(m_HandleKeyUp);

            // handle key up
            m_HandleInputChar = new NCheckBox("Handle Input Char");
            stack.Add(m_HandleInputChar);

            // Create the events log
            m_EventsLog = new NExampleEventsLog();
            stack.Add(m_EventsLog);

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

Demonstrates the keyboard support in NOV. Click on the canvas and start pressing the keyboard keys to see the keyboard events that NOV sends to the application. Keyboard support is available to most desktop enviroments.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Keyboard Input", "https://www.nevron.com/docs/openvision/ui-keyboard-input.html"), ("User Input", "https://www.nevron.com/docs/openvision/ui-user-input.html"), }; } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields NCheckBox m_HandleKeyDown; NCheckBox m_HandleKeyUp; NCheckBox m_HandleInputChar; NCanvas m_Canvas; NExampleEventsLog m_EventsLog; string m_sInputString = ""; #endregion #region Static Methods #endregion #region Constants private const string EnglishLanguageName = "English (US)"; private const string BulgarianLanguageName = "Bulgarian"; private const string GermanLanguageName = "German"; #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Keyboard Events Example for Blazor Solution

Related Documentation Links