Escolar Documentos
Profissional Documentos
Cultura Documentos
1
Objectives
• How to create a MessageBox
• How to add functionality to MessageBox
buttons
• How to create a Form
• How to create a Form that is a program’s
main window
2
Objectives
3
Creating a MessageBox
4
Creating a MessageBox
6
Creating a MessageBox
7
Adding Functionality to MessageBox
Buttons
• DialogResult is an enumeration, or list of values that
correspond to a user’s potential MessageBox button
selection
8
Adding Functionality to MessageBox
Buttons
10
Creating a Form
• Output of CreateForm1
11
Creating a Form
• You can change the appearance, size, color, and window
management features of a Form by setting its instance
fields or properties
• The Form class contains approximately 100 properties
that can be used to set various configurations of the
Form class
• The ShowDialog() method displays a form as a modal
dialog box
12
Creating a Form
14
Creating a Form that is a Program’s Main
Window
15
Creating a Form that is a Program’s Main
Window
• When you want to add property settings to a program’s
main window, you can do so within the class constructor
16
Creating a Form that is a Program’s Main
Window
17
Placing a Button on a Window
18
Placing a Button on a Window
19
Using the Visual Studio IDE to Design a
Form
• Using a text editor when programming and designing
GUIs is a very tedious and error prone task
• Just determining an attractive and useful layout in which
to position all components on your Form takes many
lines of code and a lot of trial and error
• The Visual Studio IDE provides a wealth of tools to help
make the Form design process easier
20
Understanding the Code Created by the IDE
21
Understanding the Code Created by the IDE
22
Adding Functionality to a Button on a Form
23
Adding Functionality to a Button on a Form
25
Adding a Second Button to a Form
28
Using the Visual Studio Help Search
Function
30
Chapter Summary
• You can create a child class from Form that becomes the
main window of an application. When you create a new
main window, you must derive a new custom class from
the base class System.Windows.Forms.Form, you must
also write a Main() method that calls the
Application.Run() method.
• A window is more flexible than a MessageBox because
you can place manipulatable Window components where
you like on the surface of the window
• The Visual Studio IDE provides a wealth of tools to help
make the Form design process easier
31
Chapter Summary
32