Forms and Dialogs
An introduction to Forms and Dialogs

What’s the difference?

Dialogs are modal, Forms are non-modal. Which just means that when you show a dialog, the program blocks further input until the dialog is closed. A form however allows for input to continue. Let’s look at a simple example.

using Eto.Forms;
var form = new Form()
{
Width = 100,
Height = 100
};
form.Show();
var dialog = new Dialog()
{
Width = 100,
Height = 100
};
dialog.ShowModal(); // <-- Code execution stops here

If you paste this into your script editor and run, the Form will show, and then the dialog, however code written after the dialog will not be run until the dialog is closed. It is important to choose a Form or Dialog correctly. It can however be changed easily later on without too much extra effort.

Forms

Forms are best used when you want to present information or controls to the user that mix input between the form and the parent window, i.e Rhino. If you want users to be able to run commands and interact with Rhino, a form is the most flexible choice.

For example, a form would be best suited to a help window that the user might consult whilst using Rhino, or a window of custom visibility modes.

Dialogs

Dialogs are best used when you need to force the user to make a decision before continuing. For example, choosing a file to open, or alerting the user that an error has occurred.

Dialog is available in two flavours, Dialog, and Dialog<T>. Dialog<T> returns a result on closing which is very useful for obtaining a users choice, such as Ok, Cancel or even a filename.

Semi-Model Dialogs

Dialogs can also be run as semi-modal, meaning, code execution is blocked, but the user can still input information to the command line and interact with Rhino.

using Eto.Forms;
using Rhino.UI;
var dialog = new Dialog() {
Width = 100,
Height = 100
};
var parent = RhinoEtoApp.MainWindowForDocument(__rhino_doc__);
// DefaultButton and AbortButton is required for SemiModal
dialog.DefaultButton = new Button();
dialog.AbortButton = new Button();
dialog.ShowSemiModal(__rhino_doc__, parent); // <-- Code execution stops here
Type Stops Code Execution Prevents input outside the window
Form
Dialog ✔️ ✔️
Dialog (SemiModal) ✔️