Simple applications consist of a main window, which has multiple functions it both displays the main data over which the application operates and exposes the functionality to process that data through user interface (UI) mechanisms like menu bars, tool bars, and status bars. A non-trivial application may also display additional windows to do the following:
These types of windows are known as dialog boxes, and there are two types: modal and modeless.
A modal dialog box is displayed by a function when the function needs additional data from a user to continue. Because the function depends on the modal dialog box to gather data, the modal dialog box also prevents a user from activating other windows in the application while it remains open. In most cases, a modal dialog box allows a user to signal when they have finished with the modal dialog box by pressing either an OK or Cancel button. Pressing the OK button indicates that a user has entered data and wants the function to continue processing with that data. Pressing the Cancel button indicates that a user wants to stop the function from executing altogether. The most common examples of modal dialog boxes are shown to open, save, and print data.
A modeless dialog box, on the other hand, does not prevent a user from activating other windows while it is open. For example, if a user wants to find occurrences of a particular word in a document, a main window will often open a dialog box to ask a user what word they are looking for. Since finding a word doesn't prevent a user from editing the document, however, the dialog box doesn't need to be modal. A modeless dialog box at least provides a Close button to close the dialog box, and may provide additional buttons to execute specific functions, such as a Find Next button to find the next word that matches the find criteria of a word search.
These can be sub-divided into three categories
- Display specific information to users.
- Gather information from users.
- Both display and gather information.
These types of windows are known as dialog boxes, and there are two types: modal and modeless.
A modal dialog box is displayed by a function when the function needs additional data from a user to continue. Because the function depends on the modal dialog box to gather data, the modal dialog box also prevents a user from activating other windows in the application while it remains open. In most cases, a modal dialog box allows a user to signal when they have finished with the modal dialog box by pressing either an OK or Cancel button. Pressing the OK button indicates that a user has entered data and wants the function to continue processing with that data. Pressing the Cancel button indicates that a user wants to stop the function from executing altogether. The most common examples of modal dialog boxes are shown to open, save, and print data.
A modeless dialog box, on the other hand, does not prevent a user from activating other windows while it is open. For example, if a user wants to find occurrences of a particular word in a document, a main window will often open a dialog box to ask a user what word they are looking for. Since finding a word doesn't prevent a user from editing the document, however, the dialog box doesn't need to be modal. A modeless dialog box at least provides a Close button to close the dialog box, and may provide additional buttons to execute specific functions, such as a Find Next button to find the next word that matches the find criteria of a word search.
These can be sub-divided into three categories
- Message Boxes
- Common Dialog Boxes
- Custom Dialog Boxes
Message Boxes
A message box is a dialog box that can be used to display textual information and to allow users to make decisions with buttons. The following figure shows a message box that displays textual information, asks a question, and provides the user with three buttons to answer the question.Dim messageBoxText As String = "Do you want to save changes?" Dim caption As String = "Word Processor" Dim button As MessageBoxButton = MessageBoxButton.YesNoCancel Dim icon As MessageBoxImage = MessageBoxImage.Warning Dim result As MessageBoxResult = MessageBox.Show(messageBoxText, caption, button, icon) ' Process message box results Select Case result Case MessageBoxResult.Yes ' User pressed Yes button ' ... Case MessageBoxResult.No ' User pressed No button ' ... Case MessageBoxResult.Cancel ' User pressed Cancel button ' ... End Select
Common Dialog Boxes
Windows implements a variety of reusable dialog boxes that are common to all applications, including dialog boxes for opening files, saving files, and printing. Since these dialog boxes are implemented by the operating system, they can be shared among all the applications that run on the operating system, which helps user experience consistency; when users are familiar with the use of an operating system-provided dialog box in one application, they don't need to learn how to use that dialog box in other applications. Because these dialog boxes are available to all applications and because they help provide a consistent user experience, they are known as common dialog boxes.Open File Dialog
The open file dialog box, shown in the following figure, is used by file opening functionality to retrieve the name of a file to open.
Dim dlg As New Microsoft.Win32.OpenFileDialog() dlg.FileName = "Document" ' Default file name dlg.DefaultExt = ".txt" ' Default file extension dlg.Filter = "Text documents (.txt)|*.txt" ' Filter files by extension ' Show open file dialog box Dim result? As Boolean = dlg.ShowDialog() ' Process open file dialog box results If result = True Then ' Open document Dim filename As String = dlg.FileName End If
Save File Dialog Box
The save file dialog box, shown in the following figure, is used by file saving functionality to retrieve the name of a file to save.
Dim dlg As New Microsoft.Win32.SaveFileDialog() dlg.FileName = "Document" ' Default file name dlg.DefaultExt = ".text" ' Default file extension dlg.Filter = "Text documents (.txt)|*.txt" ' Filter files by extension ' Show save file dialog box Dim result? As Boolean = dlg.ShowDialog() ' Process save file dialog box results If result = True Then ' Save document Dim filename As String = dlg.FileName End If
Print Dialog Box
The print dialog box, shown in the following figure, is used by printing functionality to choose and configure the printer that a user would like to print data to.
Dim dlg As New PrintDialog() dlg.PageRangeSelection = PageRangeSelection.AllPages dlg.UserPageRangeEnabled = True ' Show save file dialog box Dim result? As Boolean = dlg.ShowDialog() ' Process save file dialog box results If result = True Then ' Print document End If
No comments:
Post a Comment