Tutorial 1 An Introduction to Visual Basic NET

Tutorial 1 An Introduction to Visual Basic. NET Tutorial 1: An Introduction to Visual Basic. NET 1

Creating a Windows-Based Application in Visual Basic. NET Lesson A Tutorial 1: An Introduction to Visual Basic. NET 2

Lesson A Objectives After completing this lesson, you will be able to: § Start and customize Visual Studio. NET § Create a Visual Studio. NET solution § Add a Visual Basic. NET project to a solution § Set the properties of an object § Save a solution, project, and form § Close a solution § Open an existing solution Tutorial 1: An Introduction to Visual Basic. NET 3

Starting and Customizing Visual Studio. NET § Visual Studio. NET is Microsoft’s newest integrated development environment (IDE) § Includes programming languages such as Visual Basic. NET, C++. NET, and C#. NET § A Windows-based application has a Windows user interface and runs on a desktop computer § A user interface is what you see and interact with when using an application § A Web-based application, on the other hand, has a Web user interface and runs on a server Tutorial 1: An Introduction to Visual Basic. NET 4

The Visual Studio. NET Start Page Links Tutorial 1: An Introduction to Visual Basic. NET 5

Visual Studio. NET Recent Projects Toolbox Tutorial 1: An Introduction to Visual Basic. NET Solution Explorer Dynamic Help 6

Starting a New Project Installed. NET Products Name and Location Of Project Tutorial 1: An Introduction to Visual Basic. NET Type of Project Name of Project 7

Purpose of the Links Included on the Start Page Link Purpose Get Started Create new projects and open existing projects What’s New Access information about the new features in Visual Studio. NET and check for Visual Studio. NET updates Online Community Contact fellow developers online Headlines View links to the latest news from the MSDN Online Library, including information on seminars, trade shows, and conferences, as well as training opportunities offered by Microsoft Search Online Search the MSDN Online Library Downloads Access the latest product updates and sample code available for download XML Web Services Search for XML Web Services to include in your applications, and publish your own XML Web services Web Hosting Post Web applications, for a fee, on servers provided by thirdparty Internet Service Providers My Profile Customize various program settings in the IDE Tutorial 1: An Introduction to Visual Basic. NET 8

Toolbox (autohidden) Visual Basic. NET Project information Windows Form object Tutorial 1: An Introduction to Visual Basic. NET Properties window 9

Working with Controls Lesson B Objectives After completing this lesson, you will be able to: § Add a control to a form § Set the properties of a label, picture box, and button control § Select multiple controls § Center controls on the form § Set the properties of a project § Start and end an application § Enter code in the Code Editor window § Terminate an application using the Me. Close method Tutorial 1: An Introduction to Visual Basic. NET 10

Working With Controls Toolbox Item Description Data Components to access data and data sources Components to perform special tasks Clipboard Ring Stores items that you have copied General Can be used to store code snippets Windows Forms Objects used to create user interface Tutorial 1: An Introduction to Visual Basic. NET 11

The Toolbox Window § The Toolbox window, or toolbox, contains the tools and other components you use when designing a user interface § The contents of the toolbox vary depending on the designer in use Tutorial 1: An Introduction to Visual Basic. NET 12

The Windows Form Tab The Windows Form tab § Contains the tools you use when designing your user interface § Contains 47 basic tools § However, you can add new tools or delete existing tools by right-clicking the tab and then clicking Customize Toolbox on the context menu § By default, the tools on the Windows Form tab are listed in order by their estimated frequency of use, with the most used tools listed first Tutorial 1: An Introduction to Visual Basic. NET 13

Using the Label Tool § The tools in the toolbox allow you to create objects, called controls, that can be displayed on a form § You use the Label tool to create a label control § The purpose of a label control is to display text that the user is not allowed to edit while the application is running § Assigning meaningful names to the controls on a form will help you keep track of the various controls in the user interface Tutorial 1: An Introduction to Visual Basic. NET 14

Using the Label Tool § Used to display data that users cannot change Property Description Name Identifies the object in code Text Displayed information Auto. Size Determines if the object resizes itself to display all Text Location Sets the X and Y coordinates for where label is displayed Font Characteristics of the displayed Text Tutorial 1: An Introduction to Visual Basic. NET 15

Key Form Properties Property Description Name Used to refer to the object Text Caption displayed in the title bar Start. Position of window on screen Background. Image displayed on the form Size Width and Height of window Location Left and Top position of window Tutorial 1: An Introduction to Visual Basic. NET 16

Changing the Property for More Than One Control at a Time § You can use the Font property to change the appearance of many of the objects in your user interface § The Font property allows you to change the type of font used to display the text in the object, as well as the style and size of the font Tutorial 1: An Introduction to Visual Basic. NET 17

Fonts § A font is the general shape of the characters in the text § Courier, Tahoma, and Microsoft Sans Serif § Font styles include regular, bold, and italic Tutorial 1: An Introduction to Visual Basic. NET 18

Changing the Property for More Than One Control at a Time § The numbers 8, 10, and 18 are examples of font sizes, which typically are measured in points, with one point equaling 1/72 of an inch § One reason for changing a font is to bring attention to a specific part of the screen § You can change the font size for both controls at the same time by clicking one control and then pressing and holding down the Control key as you click the other control in the form Tutorial 1: An Introduction to Visual Basic. NET 19

Changing the Property for More Than One Control at a Time § You can use the Control+Click method to select as many controls as you want § To cancel the selection of one of the selected controls, press and hold down the Control key as you click the control § To cancel the selection of all of the selected controls, release the Control key, then click the form or an unselected control on the form Tutorial 1: An Introduction to Visual Basic. NET 20

Using the Format Menu § The Format menu provides options that allow you to manipulate the controls in the user interface § The Align option allows you to align two or more controls by their left, right, top, or bottom borders § You can use the Make Same Size option to make two or more controls the same width or height, or both width and height § The Format menu also has a Center in Form option that centers one or more controls either horizontally or vertically on the form Tutorial 1: An Introduction to Visual Basic. NET 21

Using the Picture. Box Tool § You can include a logo by displaying the logo in a picture box control, which you create using the Picture. Box tool Tutorial 1: An Introduction to Visual Basic. NET 22

Using the Button Tool § Every Windows application should give the user a way to exit the program § Most Windows applications provide either an Exit option on a File menu or an Exit button for this purpose § In Windows applications, a button control performs an immediate action when clicked § You create a button using the Button tool in the toolbox Tutorial 1: An Introduction to Visual Basic. NET 23

Starting and Ending an Application You can start an application by § Clicking Debug on the menu bar, and then clicking Start § Or you can simply press the F 5 key on your keyboard § When you start an application, Visual Studio. NET automatically creates a file that can be run outside of the Visual Studio. NET IDE § The file, referred to as an executable file, has the same name as the project, but with an. exe filename extension Tutorial 1: An Introduction to Visual Basic. NET 24

Writing Visual Basic. NET Code § Actions—such as clicking, double-clicking, and scrolling—are called events § The set of Visual Basic. NET instructions, or code, that tells an object how to respond to an event is called an event procedure § A class definition is simply a block of code that specifies (or defines) the attributes and behaviors of an object § When you start the application, Visual Basic. NET uses the class definition to create the object Tutorial 1: An Introduction to Visual Basic. NET 25

Writing Visual Basic. NET Code § The Class Name list box lists the names of the objects included in the user interface § The Method Name list box, on the other hand, lists the events to which the selected object is capable of responding § You use the Class Name and Method Name list boxes to select the object and event, respectively, that you want to code § To help you follow the rules of the Visual Basic. NET programming language, called syntax, the Code Editor provides you with a code template for every event procedure Tutorial 1: An Introduction to Visual Basic. NET 26

Writing Visual Basic. NET Code § The first line in the Code template is called the procedure header § And the last line is called the procedure footer § A keyword is a word that has a special meaning in a programming language § The Sub keyword is an abbreviation of the term sub procedure, which, in programming terminology, refers to a block of code that performs a specific task § The Private keyword indicates that the procedure can be used only within the class in which it is defined Tutorial 1: An Introduction to Visual Basic. NET 27

Writing Visual Basic. NET Code § The items within the parentheses are called parameters and represent information that is passed to the procedure when it is invoked § If you are using a color monitor, the keywords in the code appear in a different color from the rest of the code § A method is simply a predefined Visual Basic. NET procedure that you can call (or invoke) when needed § When you call the Me. Close method, Visual Basic. NET terminates the current application Tutorial 1: An Introduction to Visual Basic. NET 28

The Code Window Class definition Code Editor window tab Event procedure Tutorial 1: An Introduction to Visual Basic. NET 29

The Exit. Button’s Click Event Procedure Private Sub Exit. Button_Click(By. Val sender As Object, _ By. Val e As System. Event. Args) Handles Exit. Button. Click Private Sub Indicates the start of a code unit that can only be used in this class Exit. Button_Click The name of the procedures is the object name and event name connected with an underscore sender As Object Identifies the object creating the event e As System. Event. Args Identifies specific information about the event Handles Identifies the object and event that this procedure will handle Tutorial 1: An Introduction to Visual Basic. NET 30

The Event Procedure Private Sub Exit. Button_Click(By. Val sender As Object, _ By. Val e As System. Event. Args) Handles Exit. Button. Click Me. Close() End Sub Tutorial 1: An Introduction to Visual Basic. NET 31

Completing the Copyright Screen Lesson C Objectives After completing this lesson, you will be able to: § Set the properties of a timer control § Delete a control from the form § Delete the code from the Code Editor window § Code the timer control’s Tick event § Remove and/or disable the Minimize, Maximize, and Close buttons § Prevent the user from sizing a form § Print the project’s code Tutorial 1: An Introduction to Visual Basic. NET 32

Using the Timer Tool § Splash screens typically do not contain an Exit button; rather, they use a timer control to automatically remove the splash screen after a set period of time § You create a timer control using the Timer tool in the toolbox § You can use a timer control to process code at regular time intervals § You simply set the control’s Interval property to the length of the desired time interval, in milliseconds Tutorial 1: An Introduction to Visual Basic. NET 33

Using the Timer Tool § You also set its Enabled property to True § The Enabled property determines whether an object can respond to an event § You then enter the code you want processed into the control’s Tick event procedure § The Tick event procedure tells the computer what to do after each time interval has elapsed § Now that you have a timer control on the form, you no longer need the Exit button, so you can delete it and its associated code Tutorial 1: An Introduction to Visual Basic. NET 34

Setting the Form. Border. Style Property § The Form. Border. Style property determines the border style of a Windows Form object From. Border. Style setting Description Fixed 3 D Fixed, three-dimensional Fixed. Dialog Fixed, thick dialog-style Fixed. Single Fixed, thin line Fixed. Tool. Window Fixed, tool window style None No border Sizable, normal style (default) Sizable. Tool. Window Sizable, tool window style Tutorial 1: An Introduction to Visual Basic. NET 35

The Minimize. Box, Maximize. Box, and Control. Box Properties § You can use a Windows Form object’s Minimize. Box property to disable the Minimize button that appears on the form’s title bar § Similarly, you can use the Maximize. Box property to disable the Maximize button § Unlike most applications, splash screens typically do not contain a title bar § You can remove the title bar by setting the Windows Forms object’s Control. Box property to False, and then removing the text from its Text property Tutorial 1: An Introduction to Visual Basic. NET 36

Printing Your Code § You always should print a copy of the code entered in the Code Editor window, because the printout will help you understand maintain the application in the future § To print the code, the Code editor window must be the active, or current, window Tutorial 1: An Introduction to Visual Basic. NET 37
- Slides: 37