Programming with Microsoft Visual Basic 2012 Chapter 1: An Introduction to Visual Basic 2012.

Slides:



Advertisements
Similar presentations
Chapter 1: An Introduction to Visual Basic 2012
Advertisements

Using Macros and Visual Basic for Applications (VBA) with Excel
© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
© by Pearson Education, Inc. All Rights Reserved. continued …
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
Chapter 1: An Introduction to Visual Basic.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Using the Visual Basic Editor Visual Basic for Applications 1.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Microsoft Visual Basic 2010: Reloaded Fourth Edition
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Chapter 2 –Visual Basic, Controls, and Events
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2005: Reloaded Second Edition
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 4 1 Microsoft Office FrontPage 2003 Tutorial 4 – Using Shared Borders and Themes.
IE 411/511: Visual Programming for Industrial Applications
Tutorial 1: An Introduction to Visual Basic.NET1 Tutorial 1 An Introduction to Visual Basic.NET.
Chapter 1: An Introduction to Visual Basic 2005 Programming with Microsoft Visual Basic 2005, Third Edition.
Teacher: Ms. Olifer MICROSOFT VISUAL STUDIO 2010: PROPERTIES OF WINDOWS FORM OBJECT.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 2 Creating a User Interface.
 2009 Pearson Education, Inc. All rights reserved Introduction to the Visual Basic Express 2008 IDE.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
OCC Network Drives  H:\  P:\ 
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Chapter Two Designing Applications Programming with Microsoft Visual Basic th Edition.
Chapter Two Creating a First Project in Visual Basic.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Chapter 2 More Controls Programming in C#. NET Objectives Use text boxes, group boxes, check boxes, radio buttons, and picture boxes effectively.
Chapter 3 I Need a Tour Guide (Introduction to Visual Basic 2010) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Tutorial 1: An Introduction to Visual Basic.NET1 Tutorial 1 An Introduction to Visual Basic.NET.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 3 Building an Application in the Visual Basic.NET Environment.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Chapter 2 Creating Applications with Visual Basic.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
 2007 Pearson Education, Inc. All rights reserved Introduction to the Visual Basic Express 2005 IDE.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
 You won’t write a single line of program code.  Instead, you’ll use visual programming techniques.  Visual Studio processes your actions (such as mouse.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter One An Introduction to Visual Basic 2008.
Chapter 3: I Need a Tour Guide (Introduction to Visual Basic 2012)
Chapter 1: An Introduction to Visual Basic .NET
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 2: The Visual Studio .NET Development Environment
Chapter 1: An Introduction to Visual Basic 2012
Chapter 1: An Introduction to Visual Basic 2015
Chapter 2 – Introduction to the Visual Studio .NET IDE
3.01 Apply Controls Associated With Visual Studio Form
Programming with Microsoft Visual Basic th Edition
3.01 Apply Controls Associated With Visual Studio Form
Chapter 1: An Introduction to Visual Basic 2015
Introduction to the Visual C# 2005 Express Edition IDE
Program and Graphical User Interface Design
Chapter 2 – Introduction to the Visual Studio .NET IDE
CIS16 Application Development Programming with Visual Basic
Presentation transcript:

Programming with Microsoft Visual Basic 2012 Chapter 1: An Introduction to Visual Basic 2012

Lesson A Objectives After studying Lesson A, you should be able to: Start and customize Visual Studio 2012 Create a Visual Basic 2012 Windows application Manage the windows in the IDE Set the properties of an object Restore a property to its default setting Save a solution Close and open an existing solution Programming with Microsoft Visual Basic 20122

The Splash Screen Application Programming with Microsoft Visual Basic Figure 1-1 Splash screen for the Red Tree Inn

To start Visual Studio Professional 2012: –Click Start and point to All Programs –Select Microsoft Visual Studio 2012 –Click Start Visual Studio –Click WINDOW ( 視窗 ) on the menu bar –Click Reset Window Layout ( 重設視窗配置 ) –Click Yes at the prompt to restore the default layout –You can also select a different window layout using TOOLS→ Options on the menu bar Programming with Microsoft Visual Basic The Splash Screen Application (cont.) Figure 1-2 Microsoft Visual Studio Professional 2012 startup screen

Programming with Microsoft Visual Basic Setting Window Layout Figure 1-3 Options dialog box

To create a Visual Basic 2012 Windows application: –Click FILE on the menu bar, and then click New Project –Enter Splash Project in the Name Box –Locate a folder to store the project –Select Create Directory for Solution Programming with Microsoft Visual Basic The Splash Screen Application (cont.)

Programming with Microsoft Visual Basic Figure 1-4 Completed New Project dialog box in Visual Studio Professional 2012

The Splash Screen Application (cont.) Programming with Microsoft Visual Basic Figure 1-5 Solution and Visual Basic project

The Splash Screen Application (cont.) Managing the Windows in the IDE To open the Properties Window: –Click VIEW on the menu bar, and then click Properties Window –Or mouseover the Solution Explorer tab if the window is auto-hidden To close a window: –Use the Close button on the window’s title bar To minimize a window to a tab: –Click the Auto Hide (push-pin) button on the Solution Explorer window Programming with Microsoft Visual Basic 20129

10 The Splash Screen Application (cont.) Figure 1-6 Current status of the windows in the IDE

Windows Form Designer Window Programming with Microsoft Visual Basic Used to create a graphical user interface (GUI) Windows Form object –Create a UI by adding objects Buttons Text boxes –The title bar contains a default caption minimize, maximize, and close buttons Figure 1-7 Windows Form Designer window

Solution Explorer Window Programming with Microsoft Visual Basic Displays a list of projects contained in the current solution and items contained in each project Source file ( 原始檔 ) –A file containing program instructions (code) Form file ( 表單檔 ) –Contains code associated with a form –The first form’s code is stored in Form1.vb –The second form’s code is stored in Form2.vb Figure 1-8 Solution Explorer window 列出專 案內各 檔案

Properties Window Programming with Microsoft Visual Basic Properties –Attributes of objects that determine appearance and behavior Object box –Contains the name of the selected object Properties list –Helps identify and access properties Settings box –Shows the current values of properties Figure 1-9 Properties window

Properties of a Form File Programming with Microsoft Visual Basic Using the Properties window to change a form file’s name –Click Form1.vb Source file in Solution Explorer window –Click File Name in Properties list –Type Splash Form.vb.vb extension identifies file as source file –Press Enter

Properties of a Form File Programming with Microsoft Visual Basic

Properties of a Windows Form Programming with Microsoft Visual Basic System.Windows.Forms is the namespace that contains the Form class A class is a block of code that specifies an object’s appearance and behavior The period that separates each word in System.Windows.Forms.Form is called the dot member access operator Figure 1-11 Properties window showing a partial listing of the form’s properties

Important Properties of a Windows Form Programming with Microsoft Visual Basic The Name Property Windows forms have a Name property –Use it to refer to the form in the program code Naming conventions are used for clarity –Hungarian notation for a variable frmSplash : “frm” indicates a form (data type of the variable), and “Splash” is the purpose of the variable –Camel case Enter the name of a VB object in lowercase and then capitalize the first letter of each subsequent word in the name

Important Properties of a Windows Form Programming with Microsoft Visual Basic The Text Property The Text property controls the text displayed in the form’s title bar –The default text for the Text property of Form 1 is Form1 Change the default name to something meaningful –The Name property is used by the programmer –The Text property is read by the user when the application is running

Important Properties of a Windows Form Programming with Microsoft Visual Basic The StartPosition Property The computer uses the form’s StartPosition property to determine the form’s initial position on the screen –Splash screens usually appear in the middle of the screen Choose CenterScreen for the StartPosition CenterScreen WindowsDefaultLocation

Important Properties of a Windows Form Programming with Microsoft Visual Basic The Font Property A font is the general shape of a character Font styles include regular, bold, and italic Font sizes (8, 10, 12, etc.) are in points, with 1 point equaling 1/72 of an inch The recommended font for applications is Segoe (pronounced SEE-go) –This is Segoe UI, Size 18

Important Properties of a Windows Form Programming with Microsoft Visual Basic The Size Property A form can be sized by dragging the sizing handles that appear around it You also can size an object by selecting it and then pressing and holding down the Shift key as you press the up, down, right, or left arrow key on the keyboard You also can set the object’s Size property, which contains two numbers, measured in pixels: –The first number represents the width of the form –The second number represents the height of the form

Programming with Microsoft Visual Basic Setting and Restoring a Property’s Value Figure 1-12 Status of the form in the IDE Click BackColor in the Properties list and then click the list arrow in the Settings box Click the Custom tab and then click a red square to change the background color of the form to red Now, right-click BackColor in the Properties list and then click Reset on the context menu The background color of the form returns to its default setting

Programming with Microsoft Visual Basic Saving, Closing, Opening, and Exiting a Solution Saving a Solution An asterisk (*) appears on the designer tab whenever you make a change to the form Save the solution by clicking FILE on the menu bar and then clicking Save All Closing the Current Solution Click FILE on the menu bar and then click Close Solution To exit Visual Studio 2012, click FILE on the menu bar and then click Exit Opening an Existing Solution Click FILE on the menu bar, and then locate and open the solution from the list of filenames available

Programming with Microsoft Visual Basic Lesson A Summary Starting Visual Studio Configuring Visual Studio Creating a Visual Basic 2012 Windows application Resetting a window layout Closing and opening windows Auto-hiding a window Setting property values (name, text, location, font, size, background color) Saving, closing, and opening solutions Exiting Visual Studio 2012 練習 p. 21~24

Lesson B Objectives After studying Lesson B, you should be able to: Add a VB control to a form Set the properties of a label, picture box, and button control Select multiple controls Center controls on the form Open the Project Designer window Start and end an application Enter code in the Code Editor window Terminate an application using the Me.Close() instruction Run the project’s executable file Programming with Microsoft Visual Basic

Programming with Microsoft Visual Basic The Toolbox Window Class –A pattern from which an object is created Object –An instance of a class with particular settings for behaviors and attributes Toolbox window (or toolbox) –Contains tools for designing a user interface –Each tool represents a class –Controls are instantiated using tools from the toolbox VB Controls –VB GUI objects that appear on a form

The Toolbox Window (cont.) Programming with Microsoft Visual Basic Figure 1-13 Toolbox window showing the purpose of the Label tool

Programming with Microsoft Visual Basic The Label Tool Used to create a label control –Displays text that cannot be edited at run time Important properties –Name property A unique name for a control –Text property Specifies the value that appears in a label control –Location property Specifies the location of a control on a form Includes an X value and a Y value

The Label Tool (cont.) Programming with Microsoft Visual Basic Figure 1-15 Label control added to the form

Programming with Microsoft Visual Basic The Label Tool (cont.) Setting the Text Property Select the lblMsg control –Click text in the Properties list –Type A relaxing place to stay! –Press Enter –Verify that the AutoSize property is set to True Select the lblName control –Click text in the Properties list –Type Red Tree Inn –Press Enter

Programming with Microsoft Visual Basic The Label Tool (cont.) Setting the Location Property Select the lblMsg control –Click Location in the Properties list –Expand the Location property by clicking the plus box –Type 315, 175 –Press Enter Select the lblName control –Click Location in the Properties list –Expand the Location property by clicking the plus box –Type 315, 130 –Press Enter

Programming with Microsoft Visual Basic Changing a Property For Multiple Controls A control inherits the font attribute of the form –You may want to change the default values To simultaneously modify similar controls: –Click one control and then press and hold the Ctrl key –Click other similar control(s) in the form, or click and drag to group the controls –Set the property value in the Properties list

Programming with Microsoft Visual Basic Using the Format Menu The Format menu provides options to manipulate form controls –Align: Aligns selected controls by left, right, top, or bottom borders –Make Same Size: Makes the width and/or height of selected controls uniform –Center in Form: Centers one or more controls Select as the first control the one whose size or location you want to match –Called the reference control 練習 p. 30~34

Programming with Microsoft Visual Basic The PictureBox Tool Creates a picture box control –Displays an image on a form –Task box: Lists tasks associated with a picture box Use the task box to import an image into a project –Size Mode : StretchImage A project’s resource file contains imported images Figure 1-17 Open task list for a picture box Figure 1-18 Completed Select Resource dialog box

Programming with Microsoft Visual Basic The PictureBox Tool (cont.) Figure 1-19 Picture boxes added to the form 練習 p. 34~36

Programming with Microsoft Visual Basic The Button Tool Used to create a button control –Used to perform an action when clicked –Examples: OK and Cancel buttons Common means of exiting a Windows application: –Exit option on the FILE menu –Exit button

Programming with Microsoft Visual Basic Starting and Ending an Application Startup form –Displays when an application is first started The Project Designer window specifies the startup form or the executable code to be run –Right-click My Project in the Solution Explorer window and then click Open –Or, click PROJECT on the menu bar and then click Properties Application tab –Specify startup form

Starting and Ending an Application (cont.) Programming with Microsoft Visual Basic Figure 1-20 Application pane in the Project Designer window

Starting and Ending an Application (cont.) Programming with Microsoft Visual Basic Executable file A file that can be run outside of the IDE Its filename ends with.exe It is automatically created when a Visual Basic application is started Two ways to start an application in the IDE: Click DEBUG on the menu bar and then click Start Debugging Press F5 key 練習 p. 36~38

Programming with Microsoft Visual Basic The Code Editor Window Events –User actions such as click, right-click, mouse-over, … Event procedure –A set of program instructions that are processed when an event occurs Code Editor window –Provides templates for creating event procedures –To open it, right-click the form and then click View Code

Programming with Microsoft Visual Basic The Code Editor Window (cont.) Figure 1-22 Code Editor window opened in the IDE

Programming with Microsoft Visual Basic The Code Editor Window (cont.) Class Name list box –Lists names of objects included in the UI Method Name list box –Lists appropriate events for the selected object To select a control’s event in the Code Editor window: –Select the class name first –Then select the method name Syntax –The rules of a programming language

Programming with Microsoft Visual Basic Class Name and Method Name List Boxes Class Name list box Method Name list box

Programming with Microsoft Visual Basic Writing A Procedure Procedure header –The first line in the code template for an event procedure Procedure footer –The last line in the code template for an event procedure Keyword –A word that has a special meaning in a programming language –Color coded in the IDE procedure header procedure footer

Programming with Microsoft Visual Basic Event Sub Procedure Sub procedure –A block of code that performs a specific task Keywords in a sub procedure block: –Sub : Starts a sub procedure –End Sub : Indicates the end of a sub procedure –Private : Restricts the use of the procedure to the form where it appears The names of event sub procedure include the object name and event name –Example: btnExit.Click

Programming with Microsoft Visual Basic Me.Close() Instruction and IntelliSense Method –A predefined procedure –Can be called (or invoked) when needed Me.Close() method –Causes the current form to close –If it is the only form in an application, the application terminates IntelliSense feature Provides appropriate selections as pop-up lists when coding Type the first few letters of your choice Then use the arrow keys to select an item in the list 練習 p. 38~42

Programming with Microsoft Visual Basic The IntelliSense feature Figure 1-25 List displayed by the IntelliSense feature

Programming with Microsoft Visual Basic Lesson B Summary To add a control to a form, use a tool from the toolbox Use the label control for text that users cannot edit You can set the properties of multiple controls simultaneously To start and stop an application in the IDE, use DEBUG on the menu bar Use the Code Editor window to display an object’s event procedures The Me.Close() method closes the current form at run time

Lesson C Objectives After studying Lesson C, you should be able to: Set the properties of a timer control Delete a control from the form Delete code from the Code Editor window Code a timer control’s Tick event procedure Prevent the user from sizing a form Remove and/or disable a form’s Minimize, Maximize, and Close buttons Print an application’s code and interface Programming with Microsoft Visual Basic

Using the Timer Tool Splash screens typically close automatically –They do not usually contain an Exit button –Use a timer control to close the splash screen Timer tool –Used to create a timer control Timer control –Processes code at regular time intervals –Does not appear on the user interface at run time –Important properties Interval property –Specified in milliseconds Enabled property –Allows the timer to run if set to True Programming with Microsoft Visual Basic

Using the Timer Tool (cont.) Tick event –Occurs each time an interval has elapsed –Condition: The timer must enabled Add code to the Tick event procedure –Code will be run when the Tick event occurs Component tray –A special area below the form design area in the IDE –Stores controls not visible in the user interface at run time Programming with Microsoft Visual Basic

Using the Timer Tool (cont.) Programming with Microsoft Visual Basic Figure 1-29 Timer control placed in the component tray 練習 p. 48~50

FormBorderStyle Property of a Form FormBorderStyle property –Determines the border style of a form Example settings: –Sizable: Allows the user to change a form’s size by dragging its borders at run time –FixedSingle: A fixed, thin border line –None: No border Programming with Microsoft Visual Basic

The MinimizeBox, MaximizeBox, and ControlBox Properties MinimizeBox property –Determines whether the Minimize button appears on the form’s title bar MaximizeBox property –Determines whether the Maximize button appears on the form’s title bar ControlBox property –Determines whether the title bar appears on the form Splash screens typically do not contain a title bar –To remove a title bar, delete the contents of the form’s Text property Programming with Microsoft Visual Basic

Programming with Microsoft Visual Basic Figure 1-31 Completed splash screen The MinimizeBox, MaximizeBox, and ControlBox Properties (cont.) 練習 p. 50~51

Printing the Application’s Code and Interface Printing the application’s code and user interface helps you understand and maintain the application To print the interface : –Run the application –Press Prnt Scrn on the keyboard –Paste into Word or Paint and then print To print the code : –Click the Splash Form.vb tab to make the Code Editor window the active window –Click FILE on the menu bar, and then click Print to open the Print dialog box Programming with Microsoft Visual Basic

Programming with Microsoft Visual Basic Figure 1-32 Print dialog box Printing the Application’s Code and Interface (cont.)

Programming with Microsoft Visual Basic Lesson C Summary The timer control processes code at specified intervals A form’s MinimizeBox and MaximizeBox properties enable or disable the Minimize and Maximize buttons on the form A form’s ControlBox property determines whether the icon and control buttons appear in the title bar A form’s FormBorderStyle property controls the appearance of the form’s border Print Visual Basic code from the Code Editor window Print the user interface from the designer window