Title: Microsoft VB 2005: Reloaded, Advanced
1Microsoft VB 2005 Reloaded, Advanced
- Chapter 6
- More about Windows Forms
2Objectives
- Understand program code generated by Visual Basic
for user interfaces - Create a user interface with a flow layout and a
table layout - Create a user interface with tabbed pages and
dialog forms - Create a user interface with a menu and shortcut
keys - Create an application with a multiple document
interface (MDI)
3A Closer Look at GUIs
- Objective
- Understand the code generated by Visual Basic as
you build a GUI
4Forms and Components
- Form
- Window or dialog box that makes up an
applications graphical user interface - Instance of the class System.Windows.Forms.Form
- Component
- Object that is added to a form to provide
functionality - Control
- Visible component derived from the Control class
5The Event-Handling Model
- Event
- A message indicating that a user action has
occurred - Event-driven applications
- GUIs generate events (via user actions) that
drive the applications functionality - Event-handlers
- Methods written by the programmer to provide the
application with the desired responses to events - Visual Basic uses a MulticastDelegate object to
implement event handling
6The Event-Handling Model (continued)
- Delegate
- An instance of the Delegate class
- Delegate class
- Data structure that refers to either
- A static method
- A class instance and an instance method of that
class - An event generated by a GUI calls a delegate that
is registered for that event - Delegate in turn calls all methods (static
methods or instance methods) that it references
7Visual Basic Generated Code for GUIs
- When you create a GUI using the Visual Basic Form
Designer - Visual Basic generates the required program code
in the Code window - View code by right-clicking the open space in the
Windows Form Designer, outside the form - And then clicking View Code
- Details of the code for the GUI are hidden from
view - Figure 6.3 shows the code generated by Windows
Form Designer
8Visual Basic Generated Code for GUIs (continued)
9Visual Basic Generated Code for GUIs (continued)
10Enhancing a GUIs Appearance and Functionality
- Objective
- Learn tips for enhancing Windows application forms
11Form Startup Location
- By default, a form will appear at the Windows
default location - Near the upper-left corner of the screen
12Form Startup Location (continued)
13Making a Form Scrollable
- A form may contain more controls than will fit
within the boundaries of the form - You can make your form scrollable with scroll
bars that appear only when necessary - Select True for the Autoscroll property value
14Making a Form Scrollable (continued)
15Making a Form Scrollable (continued)
16Making a Form Scrollable (continued)
17The FlowLayoutPanel Control
18The FlowLayoutPanel Control (continued)
19The Margin and Padding Properties
- Margin property
- Determines the amount of space, in pixels,
reserved around a control - When calculating its automatic position in a
FlowLayoutPanel - Padding property
- Determines the amount of space, in pixels,
reserved along the inside of containers
20The Margin and Padding Properties (continued)
21The TableLayoutPanel Control
- Allows you to create a rectangular grid of rows
and columns in which other controls can be placed - Helps maintain an organized appearance for the
form
22The TableLayoutPanel Control (continued)
23The TableLayoutPanel Control (continued)
24The TableLayoutPanel Control (continued)
25The TableLayoutPanel Control (continued)
26The TabControl Control
- Allows you to create a form with several related
tabbed pages - Can consist of two or more TabPage controls, each
of which can contain various other controls
27The TabControl Control (continued)
28The TabControl Control (continued)
29Dialog Forms
- Dialog form
- Modal form that can return standard results using
the DialogResult property - Convenient way of getting quick standard
responses - Displayed using the ShowDialog method
- Modal form
- Requires the user to close the form before
activating another window in the application - Modeless form
- Does not have this requirement
30Dialog Forms (continued)
31Menus
- One of the best ways of organizing a larger
number of commands is with menus
32About Menus
- Menu
- List of items that specify options or groups of
options for an application - Menu items
- Represent the individual menu commands in a menu
- A menu item can be a parent menu for other
submenu items - Shortcut key
- Single key or a combination of keys that the user
can press to execute a menu item
33Implementing Menus
- Adding a menu
- With an empty form displayed in the Designer
- Drag a MenuStrip control from the Toolbox to any
part in the form - Adding a menu item
- See Figure 6.24
34Implementing Menus (continued)
35Implementing Menus (continued)
36Implementing Menus (continued)
- Adding shortcut keys
- See Figure 6.26 and Figure 6.27
- Adding functionality to menu items
- See Figure 6.29
37Implementing Menus (continued)
38Implementing Menus (continued)
39Multiple-Document-Interface Windows
- Single-document-interface (SDI) applications
- Applications that support only one open window or
document at a time - Multiple-document-interface (MDI) applications
- Allow many documents to be open at once
- Allow the user to easily move from document to
document - The application window of an MDI program is
called the parent window - Each window in application is called a child
window
40Multiple-Document-Interface Windows (continued)
41Multiple-Document-Interface Windows (continued)
42Multiple-Document-Interface Windows (continued)
- Example
- Birthday application
43Multiple-Document-Interface Windows (continued)
44Multiple-Document-Interface Windows (continued)
45Multiple-Document-Interface Windows (continued)
46Multiple-Document-Interface Windows (continued)
- Properties, methods, and events associated with
MDI forms - See Table 6.1
47Multiple-Document-Interface Windows (continued)
48Multiple-Document-Interface Windows (continued)
49Multiple-Document-Interface Windows (continued)
50Summary
- A form is a graphical element that appears on the
screen - A component is an object that ultimately derives
much of its functionality from the Component
class - When a user interacts with a control by using the
mouse or the keyboard - The control raises an event within the
application - When you create a GUI using the Visual Basic Form
Designer - Visual Basic generates the required program code
in the Code window
51Summary (continued)
- Enhancing GUIs
- StartPosition property
- AutoScroll property
- FlowLayoutPanel control
- Margin and Padding properties
- TableLayoutPanel control
- TabControl control
- A dialog form is a modal form that can return
standard results using the DialogResult property
52Summary (continued)
- A menu is a component of the MenuStrip class that
represents the container for the menu structure
of a form - A menu contains menu items
- All menu items can have key shortcuts (or hot
keys) - MDI applications allow many documents to be
opened at once