Professional Documents
Culture Documents
Week 9
2. Message Boxes
3. Layout Management
1. Anchor
2. Dock
3. Tab Order
Dialog Box
A dialog box is a form defined with particular properties. Like a form, a dialog box
is referred to as a container. Like a form, a dialog box is mostly used to host child
controls, insuring the role of dialog between the user and the machine. Here is an
example of a dialog box:
A dialog box is most often used to provide the user with the means for
specifying how to implement a command or to respond to a question.
Windows.Form is a base class for a dialog box.
Sometimes, in a graphical user interface, a window is used to communicate
with the user or establish a dialog between the user and the application. This
additional window is called a dialog box. It may communicate information to
the user; prompt the user for a response or both.
Dialog boxes are special forms that are non-resizable. They are also used to
display the messages to the user. The messages can be error messages,
confirmation of the password, confirmation for the deletion of a particular
record, Find-Replace utility of the word etc. There are standard dialog boxes
to open and save a file, select a folder, print the documents, set the font or
color for the text, etc.
Dialog Box - Types
The dialog boxes that are used, which are common to all Windows
Application. It performs common tasks like saving a file, choosing a font etc.
This provides a standard way to the Application interface.
The examples are given below.
FontDialog
ColorDialog
OpenDialog
SaveDialog
These dialog boxes are implemented by an operating system, so they can be
shared across all the Application that runs on that operating system
(Windows).
Custom Dialog Box
Even though common dialog boxes are useful, they do not support the
requirements of domain-specific dialog boxes. Developer need to create their
own dialog boxes.
Following steps represent the process of creating Custom Dialog Box
Add a form to your project by right clicking the project in Solution Explorer, point
to Add and then click Windows Form.
In the properties Window, change the FormBorderStyle property to FixedDialog.
Customize the appearance of the form, as required.
Add controls into this form.
Custom Dialog Box - Creation
Add another form in your project.
There are a few actions you should perform on a form to transform it into a
dialog box; but normally, these are only suggestions, not rules. Based on the
Microsoft Windows design and standards, to create a dialog box, you should
set a FormBorderStyle property to FixedDialog.
Set both the MinimizeBox and the MaximizeBox properties to False. This
causes the window to display only the system Close button.
private void InitializeComponent()
{
Text = "Domain Configuration";
Width = 320;
Height = 150;
Location = new Point(140, 100);
StartPosition = FormStartPosition.CenterScreen;
FormBorderStyle = FormBorderStyle.FixedDialog;
MinimizeBox = false;
MaximizeBox = false;
}
Custom Dialog Box
Caption of MessageBox
MessageBox.Show("Welcome to the Wonderful World of Visual C#","Visual C#
Tutorials");
Message Box
Message Box Button
Default Button:
When a message box is configured to display more than one button, the operating system
is set to decide which button is the default. The default button has a thick border that
sets it apart from the other button(s). If the user presses Enter, the message box would
behave as if the user had clicked the default button. If the message box has more than
one button, you can decide what button would be the default. To specify the default
button
MessageBox.Show("Your order appears to be correct" +"\nAre you ready to provide your
credit card information?", "Customer Order Processing",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1);
Message Box - Example
Use Following Code to display and select Color from Dialog Box
ColorDialog cd = new ColorDialog();
DialogResult cr=cd.ShowDialog();
if (cr == DialogResult.OK)
{
this.BackColor=cd.Color;
}
Font Dialog Box
To assist the user with selecting a font for an application, Microsoft Windows
provides the Font dialog box
Programmatically
button1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
Control.Dock Property
Gets or sets which control borders are docked to its parent control and
determines how a control is resized with its parent.
Programmatically
Button1.Dock = DockStyle.Top;
Tab Order
Set the tab order for the entire form by choosing Tab
Order in the menu.
Click the controls in the order you wish them to
receive focus
Select Control -> Properties -> Tab Index
As you press Tab Key while running application, focus
will switch to controller according to tab index.