Lesson 8

Using Standard Dialogs

Many applications need to display dialogs to let the user select certain standard pieces of information. Probably the most common dialogs let the user select a file to open and select a file to save into. Other dialogs let the user select colors, filesystem folders, fonts, and printers for printing.

Closely related to the print dialog are the print preview dialog (which lets the user see a preview of a printout before sending it to the printer, possibly saving paper if the user then cancels the printout) and the page setup dialog (which lets the user select things like margins before printing).

You could build all of these dialogs yourself (or you will be able to once you've finished reading this book), but why should you? If so many programs need the exact same features, why shouldn't someone build standard dialogs that everyone can use?

Happily that's exactly what Microsoft did.

C# comes with the following standard dialogs that handle these common tasks:

  • ColorDialog
  • FolderBrowserDialog
  • FontDialog
  • OpenFileDialog
  • PageSetupDialog
  • PrintDialog
  • PrintPreviewDialog
  • SaveFileDialog

Get C# 24-Hour Trainer, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.