This example demonstrates how to create a palette color picker. The palette color picker is table picker that lets the user pick a color from a palette of colors. The palette to use may be passed as a parameter to the palette color picker constructor or may be assigned to its Palette property. You can use the controls on the right to change the currently used color palette.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.DataStructures;
using Nevron.Nov.Dom;
using Nevron.Nov.Editors;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Presentation;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NPaletteColorPickerExample";
// 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
private NWidget CreateExampleContent()
{
return null;
}
private NWidget CreateExampleControls()
{
return null;
}
#endregion
#region Implementation
#endregion
#region Event Handlers
private void OnPaletteComboBoxSelectedIndexChanged(NValueChangeEventArgs args)
{
NComboBox cbPalette = (NComboBox)args.TargetNode;
switch (cbPalette.SelectedIndex)
{
case 0: // "MS Paint"
m_PaletteColorPicker.Palette = new NColorPalette(ENColorPaletteType.MicrosoftPaint);
break;
case 1: // "Office 2003":
m_PaletteColorPicker.Palette = new NColorPalette(ENColorPaletteType.MicrosoftOffice2003);
break;
case 2: // "Office 2007":
m_PaletteColorPicker.Palette = new NColorPalette(ENColorPaletteType.MicrosoftOffice2007);
break;
case 3: // "Web Safe":
m_PaletteColorPicker.Palette = new NColorPalette(ENColorPaletteType.WebSafe);
break;
}
}
private void OnSelectedIndexChanged(NValueChangeEventArgs args)
{
NPaletteColorPicker colorPicker = (NPaletteColorPicker)args.TargetNode;
NColor selectedColor = colorPicker.SelectedColor;
m_EventsLog.LogEvent(selectedColor.GetHEX().ToUpper());
}
#endregion
#region Fields
private NPaletteColorPicker m_PaletteColorPicker;
private NExampleEventsLog m_EventsLog;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
} | Language: VB.NET |
Imports Nevron.Nov
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Editors
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Forms
Public Class Form1
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Text = "NOV WinForms - NPaletteColorPickerExample"
' Create the NOV example and its controls
Dim exampleContent As NWidget = CreateExampleContent()
Dim exampleControls As NWidget = CreateExampleControls()
If Not exampleControls Is Nothing Then
exampleControls.PreferredWidth = 300
End If
' Place the example and its controls in a pair box
Dim pairBox As NPairBox = 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
Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
host.Dock = DockStyle.Fill
Controls.Add(host)
End Sub
#End Region
#Region "Example"
Private Function CreateExampleControls() As NWidget
Return Nothing
End Function
Private Function CreateExampleContent() As NWidget
Return Nothing
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
Private Sub OnPaletteComboBoxSelectedIndexChanged(args As NValueChangeEventArgs)
Dim cbPalette = CType(args.TargetNode, NComboBox)
Select Case cbPalette.SelectedIndex
Case 0 ' "MS Paint"
m_PaletteColorPicker.Palette = New NColorPalette(ENColorPaletteType.MicrosoftPaint)
Case 1 ' "Office 2003":
m_PaletteColorPicker.Palette = New NColorPalette(ENColorPaletteType.MicrosoftOffice2003)
Case 2 ' "Office 2007":
m_PaletteColorPicker.Palette = New NColorPalette(ENColorPaletteType.MicrosoftOffice2007)
Case 3 ' "Web Safe":
m_PaletteColorPicker.Palette = New NColorPalette(ENColorPaletteType.WebSafe)
End Select
End Sub
Private Sub OnSelectedIndexChanged(args As NValueChangeEventArgs)
Dim colorPicker = CType(args.TargetNode, NPaletteColorPicker)
Dim selectedColor As NColor = colorPicker.SelectedColor
m_EventsLog.LogEvent(selectedColor.GetHEX().ToUpper())
End Sub
#End Region
#Region "Fields"
Private m_PaletteColorPicker As NPaletteColorPicker
Private m_EventsLog As NExampleEventsLog
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class