Dialogs

Dialog or dialog boxes are basically pop-up windows that (usually) present a short bit of information or ask a simple question, before the user dismisses the pop-up window or provides a response (respectively). You've likely had loads of experience with dialog boxes in the past, perhaps without knowing that was their technical name. "Would you like to save before exiting? (with yes/no/cancel options)". "This Excel macro/calculation formula isn't correct for X, Y, and Z reasons." "An unexpected error has occurred with your program."

Dialog boxes are a great way to get the user's attention for a brief moment, but you want to be careful not to abuse this. Creating an excessive number of pop-up windows can not only be frustrating, it can be the sign of a poorly designed/explained process or use-case. The common type of dialog box is modal, where the rest of the application is rendered inactive while the dialog box is active. This can be helpful in preserving the state of the application while you save it in someway, or search through a file directory to load in one or more input files. Here are some of the types of dialog boxes available for us:

  1. Open File Dialog: generates a file directory search pop-up, that returns the absolute path to the file selected. This is accessible via the FileName property of the dialog.

  2. Save File Dialog: functionally similar to Open File, except data will be saved to the selected file. Again, the absolute path to that file will be accessible via the FileName property of this dialog.

  3. Print Dialog: generates a print menu pop-up window, allowing the user to define which printer to use, single or double-sided printed, etc.

  4. Font Dialog: generates a text modification pop-up window, allowing the user to choose from a list of available typefaces, sizes, styles (e.g. bold, italicized, underlined), and text colors. These are "returned" via Font and Color properties of the Font Dialog.

  5. Color Dialog: generates a color selector pop-up window, allowing the user to choose the RGB values of their intended color, or pick from the graphical display and sliders. The Color property of this dialog stores their selection.

Let's look at an example of this, capturing information from the Font Dialog.

private void fontButton_Click(object sender, EventArgs args)
{
if (fontDialog.ShowDialog() != DialogResult.Cancel) // If the user didn't hit cancel
{
someText.Font = fontDialog.Font; // Then apply the requested changes
someText.ForeColor = fontDialog.Color;
}
}