This example demonstrates how to create and use the open and save file dialogs provided by NOV.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Dom;
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.Text;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NFileDialogsExample";
// 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_TextBox = new NTextBox();
m_TextBox.Multiline = true;
m_TextBox.AcceptsEnter = true;
m_TextBox.AcceptsTab = true;
m_TextBox.VScrollMode = ENScrollMode.WhenNeeded;
m_TextBox.Text = "This is a sample text.\n\nYou can edit and save it.\n\nYou can also load text from a text file.";
return m_TextBox;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
stack.FillMode = ENStackFillMode.Last;
stack.FitMode = ENStackFitMode.Last;
// create the buttons group
NGroupBox buttonsGroup = new NGroupBox("Open Dialogs from Buttons");
stack.Add(buttonsGroup);
NStackPanel buttonsStack = new NStackPanel();
buttonsStack.Direction = ENHVDirection.TopToBottom;
buttonsGroup.Content = buttonsStack;
NButton openButton = new NButton("Open File...");
openButton.Content.HorizontalPlacement = ENHorizontalPlacement.Center;
openButton.Click += OnOpenButtonClick;
buttonsStack.Add(openButton);
NButton openMultiselectButton = new NButton("Choose Multiple Files...");
openMultiselectButton.Content.HorizontalPlacement = ENHorizontalPlacement.Center;
openMultiselectButton.Click += OnMultiselectOpenButtonClick;
buttonsStack.Add(openMultiselectButton);
NButton saveButton = new NButton("Save to File...");
saveButton.Content.HorizontalPlacement = ENHorizontalPlacement.Center;
saveButton.Click += OnSaveButtonClick;
buttonsStack.Add(saveButton);
// create the menu group
NGroupBox menuGroup = new NGroupBox("Open Dialogs from Menu Items");
stack.Add(menuGroup);
NMenuBar menuBar = new NMenuBar();
menuBar.HideGripperAndPendant();
menuGroup.Content = menuBar;
NMenuDropDown fileMenu = new NMenuDropDown("File");
menuBar.Items.Add(fileMenu);
NMenuItem openFileMenuItem = new NMenuItem("Open File...");
openFileMenuItem.Click += OnOpenFileMenuItemClick;
fileMenu.Items.Add(openFileMenuItem);
NMenuItem saveFileMenuItem = new NMenuItem("Save File...");
saveFileMenuItem.Click += OnSaveFileMenuItemClick;
fileMenu.Items.Add(saveFileMenuItem);
// create the dialog group
NGroupBox dialogGroup = new NGroupBox("Open Dialogs from Dialog");
stack.Add(dialogGroup);
NButton showDialogButton = new NButton("Show Dialog...");
showDialogButton.Click += OnShowDialogButtonClick;
dialogGroup.Content = showDialogButton;
// add the events log
m_EventsLog = new NExampleEventsLog();
stack.Add(m_EventsLog);
return stack;
}
public string GetExampleDescription()
{
return @"
This example demonstrates how to create and use the open and save file dialogs provided by NOV.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Common Dialogs", "https://www.nevron.com/docs/openvision/ui-common-dialogs.html"),
("Top Level Windows", "https://www.nevron.com/docs/openvision/ui-top-level-windows.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
private void OnOpenButtonClick(NEventArgs args)
{
ShowOpenFileDialog();
}
private void OnMultiselectOpenButtonClick(NEventArgs args)
{
ShowMultiselectOpenFileDialog();
}
private void OnSaveButtonClick(NEventArgs args)
{
ShowSaveFileDialog();
}
private void OnOpenFileMenuItemClick(NEventArgs arg1)
{
ShowOpenFileDialog();
}
private void OnSaveFileMenuItemClick(NEventArgs arg1)
{
ShowSaveFileDialog();
}
private void OnShowDialogButtonClick(NEventArgs arg1)
{
NStackPanel stack = new NStackPanel();
stack.Margins = new NMargins(10);
stack.VerticalSpacing = 10;
NButton openButton = new NButton("Open File...");
openButton.Content.HorizontalPlacement = ENHorizontalPlacement.Center;
openButton.Click += OnOpenButtonClick;
stack.Add(openButton);
NButton saveButton = new NButton("Save to File...");
saveButton.Content.HorizontalPlacement = ENHorizontalPlacement.Center;
saveButton.Click += OnSaveButtonClick;
stack.Add(saveButton);
NButtonStrip closeButtonStrip = new NButtonStrip();
closeButtonStrip.AddCloseButton();
stack.Add(closeButtonStrip);
// create a dialog that is owned by this widget window
NTopLevelWindow dialog = NApplication.CreateTopLevelWindow();
dialog.SetupDialogWindow("Show File Dialogs", false);
dialog.Content = stack;
dialog.Open();
}
#endregion
#region Fields
private NTextBox m_TextBox;
private NExampleEventsLog m_EventsLog;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
}