Sei sulla pagina 1di 22

ES26Lecture SectionC

VISUAL BASIC 2008


Chapter 2-4

Creating a Project
2

CLAddawe

ES26Lecture SectionC

Projects Templates (for VB Express)


3

Windows Forms Application Template


Lets you easily design familiar windows style applications Used to create W Windows-based applications that run locally on users' computers.

Projects Templates (for VB Express)


4

Class Library Application Template


Used to create reusable classes or components that can be shared with multiple projects. Provides a class module where custom objects can be created

CLAddawe

ES26Lecture SectionC

Projects Templates (for VB Express)


5

WPF Application Template


Used to create standalone Windows Presentation Foundation (WPF) applications. Allows you to create applications with a rich Graphical User Interface

Projects Templates (for VB Express)


6

WPF Browser Application Template


Used to create browser-hosted Windows Presentation Foundation applications.

CLAddawe

ES26Lecture SectionC

Projects Templates (for VB Express)


7

Console Application Template


Used to create command-line applications, programs that run from a Windows command prompt and have no visual interface.

Visual Studio IDE

CLAddawe

ES26Lecture SectionC

Projects and Solutions


9

In Visual Studio, programs under development are typically called projects or solutions
Because they contain many individual components (not just one file)

VB 2008 programs include:


a project file (.vbproj) and;
Contains information specific to a single programming task

a solution file ( sln) (file icons have a tiny 9 in them = VB 9) (.sln)


Are useful to manage multiple related projects Note: For a solution having a single project, opening the project file is the same as opening the solution file. But for a multi-project solution, the solution file must be opened.

Visual Studio IDE


10

Microsoft Visual Studio Integrated Development Environment (IDE) Menus, tools, component windows (tool windows)
Menu bar Standard toolbar Designer (Form Window) Solution Explorer Properties window Toolbox *Code editor window

CLAddawe

ES26Lecture SectionC

Visual Studio IDE


11

Menu bar - provides access to most of the commands that control the development environment Standard Toolbar a collection of buttons that serve as shortcuts for executing commands and controlling the Visual Studio IDE

Visual Studio IDE


12

Designer
user i interface or f f form; acts as a container for Controls to be used in the application.

CLAddawe

ES26Lecture SectionC

Visual Studio IDE


13

Properties Show ll fil Sh all files

View Code View Designer

Solution Explorer
An A area of the IDE that f h h contains your solution Helps you manage your project files. The files are displayed in a hierarchical view, much like that of Windows Explorer

Refresh

Visual Studio IDE


14

Properties Window
Used U d to change the characteristics, h h h i i or property settings, of the UI elements o a form A property setting is a quality of one of the objects in your program Changing properties:
Design time (Properties window) Run time (Code Editor)

CLAddawe

ES26Lecture SectionC

The Visual Studio Tools


15

Object list- itemizes all the UI elements (objects) on the form Properties list Property settings

Events button Properties button Alphabetical button Categorized button

Visual Studio IDE


16

Toolbox
a container f all the i for ll h controls

CLAddawe

ES26Lecture SectionC

Toolbox Tabs
Tab Name All Windows Form Common Controls Containers Description Contains all the standard Windows Forms controls that are available in the Toolbox. Contains the most common controls that are typically used in Windows-based pp applications. Contains controls that hold other controls, such as GroupBox controls and Panel controls. Containers can help isolate a set of controls from other controls on the form. Contains controls that enable you to create menus and toolbars for your application, such as the MenuStrip and ToolStrip controls. Contains controls that help you easily work with data in your application, such as the DataGridView control. Contains components that typically do not have a user interface, such as the Timer and the ErrorProvider. Contains controls that enable you to provide printing capabilities to an application. Contains controls that let you use common dialog boxes in your application, such as the SaveFileDialog, FolderBrowserDialog and FontDialog controls.

Menus and ToolBars Data Components Printing Dialogs


17

18

IDE Features

CLAddawe

ES26Lecture SectionC

Auto hide pushpin

19

IDE Features

20

Docking guides

CLAddawe

10

ES26Lecture SectionC

21

Switching among files and tools using the IDE Navigator


IDE Navigator-a feature that allows the user to cycle through open files and tools by using key combinations (Ctrl+Tab; Ctrl+Shift+Tab reverse direction) Press Alt+F7 or Shift+Alt+F7 to cycle through open tools without opening the IDE Navigator

22

Creating the User Interface

CLAddawe

11

ES26Lecture SectionC

Terminology (OOP)
23

Control
A tool used to create objects in a VB program (most commonly commonly, objects are created on a form; controls are selected from the toolbox and then drawn on the form Different ways of adding controls to the Form:
By double-clicking (default size) Drag and drop (default size) Click and drag

Terminology (OOP)
24

Object
An element that you create in a VB program with a control in the Toolbox Technically speaking objects are instances of a class that supports properties, methods and events Has inherent functionality - they know how to operate and can respond to certain situations on their own (e.g. a list box knows how to scroll)

CLAddawe

12

ES26Lecture SectionC

Terminology (OOP)
25

Class
A blueprint or template for one or more objects that defines what the object does (but is not the object itself) In Visual Basic, you can use existing Visual Studio classes (like System.Math and System.Windows.Forms.Form) and you can build your own classes and inherent properties, methods and events from them
Note: Inheritance allows one class to acquire the pre-existing interface and behavior characteristics of another class

Terminology (OOP)
26

Namespace
A hierarchical library of classes organized under a unique name (e.g. System.Windows and System.Diagnostics) Note: To access the classes and underlying objects within a namespace, place an Imports statement at the top of your program code

CLAddawe

13

ES26Lecture SectionC

Terminology (OOP)
27

Property
A value or characteristic held by an object Setting a property:
Design time using the Properties window Run time using statements in the program code
Object.Property =Value e.g. Label1.Text = Hello! Me.BackColor=Color.Yellow

Event procedure
A block of code that is executed when an object is manipulated in a program

Terminology (OOP)
28

Method
A special statement that performs an action or a service for a particular object in a program Notation:
Object.Method(Value) e.g. Textbox1.Clear() Me.Hide() Listbox1.Items.Add(Check)

CLAddawe

14

ES26Lecture SectionC

Interface Styles
29

Single-Document Interface (SDI)


Only O l one d document at a time is opened i i d

Multiple-Document Interface (MDI)


Multiple forms within a single container form

Explorer-Style Interface
a single window containing two panes or regions, usually consisting of a tree or hierarchical view on the left and a display area on the right

Interface Styles
30

Single-Document Interface (SDI)

CLAddawe

15

ES26Lecture SectionC

Interface Styles
31

Multiple-Document Interface (MDI)

Interface Styles
32

Explorer-Style Interface

CLAddawe

16

ES26Lecture SectionC

33

Interface Design

Positioning of objects
34

More important elements must be readily apparent to the user Most user's eyes will be drawn to the upper left portion of the screen first.
Organize the user interface so that the information flows either vertically or horizontally, with most important information always located in the upper-left corner of the screen

CLAddawe

17

ES26Lecture SectionC

Positioning of objects
35

Grouping of elements and controls is also important.


Group related objects together using either white space space, GroupBox, or Panel
Under Containers category in the Toolbox

The use of white space can help emphasize elements and improve usability

Consistency of interface elements


36

Inconsistency makes your application confusing, chaotic, disorganized and cheap Establish a design strategy and style conventions before you begin development Try to use controls appropriately Keep it simple

CLAddawe

18

ES26Lecture SectionC

Tooltip control
37

Tooltip an object used to provide visual clues to the function of an object f nction

Tips on GUI design


38

Images and Icons


The use of pictures and icons can also add visual interest to your application, but again, careful design is essential

Choosing Fonts
select fonts that will be easily readable at different resolutions and on different types of displays

CLAddawe

19

ES26Lecture SectionC

Tips on GUI design


39

Use meaningful captions or text in all objects Label each control in the user interface Align the labels and controls in the user interface snaplines Blue and pink snaplines

Naming Objects
40

Must begin with a letter Can contain letters and numbers Cannot contain a period
It is better to prefix a name with letters representing the kind of object they are naming to eliminate confusion especially when the application contains many objects Use meaningful names

CLAddawe

20

ES26Lecture SectionC

41

Writing the code

Writing the code


42

Code Editor Window


Contains program statements associated with the form p g Program statements that are used together to perform some action are typically grouped in a programming construct called a procedure Procedures are typically executed when certain events occur (e.g. when a button is clicked)
When a procedure is associated with a particular object and event, it is called an event handler or an event procedure.

Class Name

Method Name

CLAddawe

21

ES26Lecture SectionC

Running a Visual Basic Program


43

Click the Start Debugging button Press F5 Click the Start Debugging command on the Debug menu

Building Executable Files


44

Creating an application for Windows (.exe) Two types of files that can be created: yp Debug build
Stored in a folder called bin\debug within the project folder Contains debugging information that makes the program slightly slower

Release build
Stored in a folder called bin\release within the project folder Optimized executable files

CLAddawe

22

Potrebbero piacerti anche