Learning objectives of this chapter include The Integrated development environment (IDE) is used for modern software development; the IDE contains tools to write code, build a GUI , and test and debug applications; overview of the application construction process; design issues are addressed;...
CHAPTER TWO Creating Simple Visual Basic NET Windows Applications 2- Chapter Introduction • The Integrated Development Environment (IDE) is used for modern software development • The IDE contains tools to write code, build a GUI , and test and debug applications • Overview of the application construction process • Design issues are addressed • Visual Basic NET controls are examined • The MsgBox statement and InputBox() function are visited • A project is developed as a working application McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- Objectives • Design and construct simple complete applications from scratch • Explain the structure of Visual Basic NET • List the characteristics of several Visual Basic NET controls • Identify the purpose of each major control of the Visual Basic NET IDE • Explain basic programming practices that contribute to the readability of programs McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2.1 From New Solution to Finished Application • Overview of the Construction Process – Visual Basic NET runs under Windows – The programmer creates the application – The project is an application under construction – The application is saved to disk periodically – An executable file is generated from the finished application program McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- 2- Visual Basic NET’s Three Modes • Design Mode – Placing, arranging, and customizing the appearance of buttons, labels, and other controls on a form – Writing processing scripts (source code) – Saving the solution – Making an executable file McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved Visual Basic NET’s Three Modes (cont.) • Run Mode – Executes the solution – Used to evaluate the workability of a part of the project – Used to show the user how the solution will work McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- Visual Basic NET’s Three Modes (cont.) • Break Mode – Helps the developer with debugging – Enables the developer to switch back to run mode or design mode McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- 2- Design Time and Run Time • In design mode, the project is in design time • In run mode, the project is in run time • Some errors can be found and corrected in design time • Other errors can only be detected during run time McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- 2.2 Overview of Controls • Standard controls are used to create userfriendly applications • Standard controls help users lower the learning curve for new programs McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- 10 Categories of Controls • Trigger: Initiate processing – Ex Button, MainMenu, and Timer • Input: Get data from user – Ex TextBox, RadioButton, and CheckBox • Output: Display results to user – Ex Label, DataGrid, and ListView McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved Common Properties of the Label Control • • • • • Name AutoSize BorderStyle DataBindings Font McGraw-Hill/Irwin • • • • • 2- 28 ForeColor Image ImageAlign Text TextAlign ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- 29 Events • Example 2.1 Using the Label Control – Demonstrates two main uses of the Label control • To display a message to the user • To display “labeling” information for the user McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- 30 2.7 The TextBox Control • Provides an area for the user to type while the program runs McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- 31 Appearance and Use • Displays as a rectangular area that provides the user a place to type • You can limit the user types • You can also surround the TextBox with a border McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- 32 Properties • Some of the TextBox control properties are only available at run time • The value of the Text property is used most frequently • Control of user entry is shared between properties and events • The PasswordChar property allows you to set a security character McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- 33 Properties (cont.) • TextLength property determines the number of characters contained in a textbox • Selection… properties provide information on user selections in the TextBox control McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved Common Properties of the TextBox Control • • • • • • • • • • • Name AcceptsReturn AcceptsTab AutoSize BorderStyle CharacterCasing Font Lines MaxLength Modified Multiline McGraw-Hill/Irwin • • • • • • • • • • 2- 34 PasswordChar ReadOnly ScrollBars SelectedText SelectionLength SelectionStart Text TextAlign TextLength WordWrap ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- 35 Events Focus means the user is currently working with the specific control • Enter - Occurs when input focus is received • KeyPress - Occurs when a key is pressed while the control has focus • Leave – Occurs when input focus leaves the control McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- 36 Events (cont.) • Methods – Enable the developer to manipulate text in a TextBox – Many are available to the developer McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved Common Events for the TextBox Control • • • • • • Enter KeyPress Leave AppendText Clear Copy McGraw-Hill/Irwin • • • • • • 2- 37 Cut Cut Paste Select SelectAll Undo ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2.8 The MsgBox Statement and InputBox Function 2- 38 • Two alternate ways to receive information from the user and to display information on the screen McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- 39 MsgBox Statement • The MsgBox statement will display information that requires user intervention – MsgBox(“A prompt”, Buttons,”A title”) McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- 40 InputBox() Function • The InputBox() function requests information from the user with a dialog box It requires user intervention – InputBox(“A prompt”,”A title”,”A default response”) McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- 41 Chapter Summary • An application being developed in Visual Basic NET is called a project • Visual Basic NET uses three modes of operation • The Visual Basic NET IDE contains a number of development tools • During the design phase, descriptive names should be applied to important controls McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved 2- 42 Chapter Summary (cont.) • The Windows Form control is used to contain the other GUI controls • The Button control enables the user to trigger a process by a click event • The MsgBox statement provides an alternate means to provide information to the user • The InputBox() function provides an alternate way to receive information from the user McGraw-Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc All rights reserved ... reserved 2- Objectives • Design and construct simple complete applications from scratch • Explain the structure of Visual Basic NET • List the characteristics of several Visual Basic NET controls... Process – Visual Basic NET runs under Windows – The programmer creates the application – The project is an application under construction – The application is saved to disk periodically – An executable... Summary • An application being developed in Visual Basic NET is called a project • Visual Basic NET uses three modes of operation • The Visual Basic NET IDE contains a number of development tools