Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 21 Creating Applications with Visual Basic.NET Chapter 2.

Similar presentations


Presentation on theme: "Chapter 21 Creating Applications with Visual Basic.NET Chapter 2."— Presentation transcript:

1 Chapter 21 Creating Applications with Visual Basic.NET Chapter 2

2 2 VB Modes DesignBuild and modify the project: Place, arrange, and customize controls. Write processing scripts. Save the project. RunRun project as a user: Test components during development. Demonstrate program to user during development. BreakTemporarily suspend run mode: Examine status of processing. Determine cause of problems.

3 Chapter 23 Example Modes Design Run (see error message) Break (click Debug to see error location) Stop (Ctrl+Break)

4 Chapter 24 VB Structure Create and name a project. Folder created with same name so enter name correctly the first time! Project Forms and other necessary components to run a program Form Individual window interface (GUI background) Contains 1 or more controls General declarations

5 Chapter 25 Controls Objects on a form Labels, command buttons, text boxes, etc. (each with specific purpose and appearance) Properties Attributes defining characteristics of control Visual appearance Alignment Caption Default behavior of control at run time

6 Chapter 26 Event Procedures Signal generated at run time indicating that something (action) has occurred to which the application must respond. Caused by user actions, such as clicking a command button, double-clicking, or mouse over. Based on type of control. Event Procedure: script of detailed instructions.

7 Chapter 27 Control Planning Grid

8 Chapter 28 Open Chapter1GrossPay project Open project file (*.sln). See pp. 57-58 for more information.

9 Chapter 29 Form Properties Text (appears in title bar) Weekly Pay Calculator StartPosition (location of form at Run time) Default: WindowsDefaultLocation Change to: CenterScreen (explore other options on your own)

10 Chapter 210

11 Chapter 211 Controls (Review) Refer to Table 1-2 on page 9 for a list of controls. Input from User (text box, check box, etc.) Output to User (label, image, etc.) Trigger processing (command button, menu, etc.)

12 Chapter 212 Control Naming Conventions PrefixControlExample btnButtonbtnExit lblLabellblName txtTexttxtName

13 Chapter 213 Insert Controls

14 Chapter 214 Form Properties Review TextDisplays text in title bar StartPositionControls location of form at run time SizeControls height and width of the form IconDisplays icon image in top left corner of title bar BackColorSpecifies the background color of the form

15 Chapter 215 FormBorderStyle Controls the border for the form ValueDescription Sizable (default)Enables the minimize, maximize, and close buttons. NoneDisplays form without a border, title bar, and sizing buttons. Fixed3DDisplays the form at specific size; can minimize and maximize, but can’t manually resize the form.

16 Chapter 216 Properties Window (p. 60) CategorizedAlphabetized

17 Chapter 217 Control Properties TextAlignLocation of Text value (MiddleCenter) (p. 49) BackColorBackground color (Light Yellow) ForeColorText color (Blue)

18 Chapter 218 Control Size & Alignment Click, Ctrl, Click to select. Choose Format>Align. Choose Format>Make Same Size>Both Click + to see details, such as specific width and height

19 Chapter 219 Control Sizes Select multiple controls. Choose Format > Make Same Size > Height Width Both Look at Width and Height property settings.

20 Chapter 220 Equal Spacing between Controls Select controls of similar type. Format > Vertical Spacing > Make Equal. Format > Horizontal Spacing > Make Equal.

21 Chapter 221 Control Properties Labels Name: lbl prefix Text: text to display during Run Time TextAlign: Alignment of text within label control (p. 49) Font options Visible: Boolean can hold only True or False (Discuss reasons for setting to False. See pp. 62-63.) Text Boxes Name: txt prefix Text: empty (delete existing text) Font options Buttons Name: btn prefix Enabled: whether can respond to user Text: text displayed within button control 3 rd Button Style Property: 1-Graphical 3 rd Button Picture: image selected

22 Chapter 222 AutoSize Control Property Specifies control’s sizing abilities False (default) maintains control’s design time size; only partial Text value displayed if too much for size. True enables control’s size to expand automatically to accommodate Text property value

23 Chapter 223 BorderStyle (for Labels) NoneDescriptive label Fixed 3DOutput FixedSingleOutput

24 Chapter 224 Design After Initial Creation Buttons: Format>Make Same Size>Both Format>Horizontal Spacing>Make Equal TextAlign property values (see Figure 2-13 on p. 49)

25 Chapter 225 MS Word Font Dialog Box What control attributes do you see? Alignment Capitalization Tab Order Access Keys

26 Chapter 226 Focus (pp. 106-111) Ability of a control to enable the user to interact with the program by using the keyboard. Text Box: Enter text Button: Press Enter to trigger event Label: Can’t directly receive focus; passes to control with next TabIndex value. Only one control can have focus at a time. Control w/ focus is active control. Lose focus when go to another control.

27 Chapter 227 Focus Method Example: txtFirstName.Focus() Method action: Positions insertion point in a text box to receive input. Displays dotted borer around button. Useful in event procedure to set focus to first text box on a form

28 Chapter 228 TabIndex Property (pp. 107-111) Specifies order of pressing Tab key to go from one control to another to receive focus. Set to avoid disorganized tab order due to sequence of inserting controls. Choose View>Tab Order for visual tab order. Starts with zero on a label (since text boxes don’t have captions). 0 for label (or check box or option button). 1 for text box relating to label Etc.

29 Chapter 229 Access Keys (pp. 110-111) Enables users to access controls with the keyboard. Displays underscore for keyboard shortcut, such as File on menu bar or Exit. Uses standard guidelines: First letter (often, not always) Other appropriate letter See other apps for examples Requires & to left of character in Text property, such as: E&xit for Exit.

30 Chapter 230 Access Key Considerations Do not assign the same access key to more than 1 control on the form. If you want to display & within the Text property, type 2 ampersand symbols: Pizza && Pasta becomes…Pizza & Pasta Assign access key to a label that describes a text box b/c a text box can’t have access key. Assign Tab Order consecutively for label and respective text box.

31 Chapter 231 Accept & Cancel Buttons (p. 113) Accept Button Triggers Click event when user presses the Enter key. OK button Cancel Button Triggers Click event when user presses the Escape key. Cancel button Form property

32 Chapter 232 Modified Interface 0 2 4 1 3 5 Assign a high #, such as 100; VB leaves original #, which duplicates another TabIndex if you don’t 678

33 Chapter 233 Event Procedures (p. 62) Button names Description (pseudocode) Procedural Flowcharts (p. 63)

34 Chapter 234 Pseudocode for Command Buttons Enter Display contents of txtFirstName Display message “, you earned $” Clear Empty contents of txtFirstName text box. Empty contents of txtHoursWorked text box. Empty contents of txtHourlyPayRate text box. Empty contents of lblGrossPay Place insertion point (set focus) in 1 st box. Exit Terminate the application.

35 Chapter 235 Close Button Event Procedure

36 Chapter 236 Code Window Text-editing window to write code and remarks Intellisense feature to automate coding (such as valid property values) Vertical line: code region Plus sign: collapsed code for simplification Minus sign: expanded code (code you typically create)

37 Chapter 237 Event Procedure Explanation Private—keyword restricting event procedure’s use to form containing its definition Sub—abbreviation for procedure (block of code that performs a task) Keywords In blue Control name Event

38 Chapter 238 Clear Button Event Pseudocode

39 Chapter 239 Clear Method ControlName.Clear () Empties the Text property value Example: txtFirstName.Clear() LabelName.Text = “” Copies empty string to label Clear method doesn’t work on labels Example: lblGrossPay.Text = “”

40 Chapter 240 Clear Button Event Procedure

41 Chapter 241 Calculate Button Pseudocode Multiplies hours worked by hourly pay rate. Displays the following string in the lblGrossPay label: FirstName contents “, you earned $” Result of calculation

42 Chapter 242 Text Output Output text property value from the text box to the label

43 Chapter 243 String Literal Output Type literal in quotation marks

44 Chapter 244 Results of Calculation Output Type expression.

45 Chapter 245 Concatenate (put together) Type & to concatenate strings for output. Press Spacebar before and after & Type _ for line continuation character and indent continued lines of code Note: We will learn ways to validate input and store results in variables before displaying output as we continue throughout the semester.

46 Chapter 246 Design Guidelines Labels close to text boxes Related options closer together Consistent space between controls Consistent space from controls to edges of form Access keys for keyboard users Buttons Right side with same width Bottom with same heights

47 Chapter 247 Review Labels Descriptive captions for input controls Output showing results Text Boxes Input text from user Buttons Trigger event procedure to do something with the inputs

48 Chapter 248 Remarks (p. 64) Comments or explanations about code Part of program but ignored by Visual Basic.NET Followed by an apostrophe 'Empties the text box for user input Program description 'Keith Mulbery 'ISYS 1200 'Assignment 1 ‘Gross Pay Calculating Program

49 Chapter 249 Reasons for Remarking Documents code for maintenance Yourself Other programmers Saves time in understanding event procedures. Helps others understand your logic in coding long procedures.

50 Chapter 250 Assignment Statement Assignment operator = Statement that copies the value on the right side of the assignment operator to the item on the left side of the assignment operator. lblGrossPay.Text = txtFirstName.Text Takes content of the Text property value of the txtFirstName control and copies it into the Text property of the lblGrossPay control. (p. 101)

51 Chapter 251 Assignment Examples Syntax: ControlName.Property Name Example: lblDirections.Visible = True Invalid Assignment: True = lblDirections.Visible

52 Chapter 252 PictureBox Control (pp. 52-53) AutoSize Adjusts automatically to fit image size; maintains proportions. CenterImage If size is larger than image, image is centered. If image is larger than control, image displayed in center and clipped to fit. Normal Aligns image with upper left corner of control; Clips images if too large for control size. StretchImage Scales image to fit within the control’s size; Stretches if image is smaller than control; Shrinks if image is larger than control.

53 Chapter 253 Locked Controls Prevents controls from being accidentally moved at design time. (1)Right-click empty area of form. (2)Choose Lock Controls.

54 Chapter 254 Types of Errors (p. 88) Compile Error Syntax errors Misspelled key words Incorrect use of operators Incorrect punctuation Jagged blue underline and description displayed Run-Time Error Not syntax Attempt to perform an operation that VB.NET can’t carry out

55 Chapter 255 Compile Errors ToolTip stating compile error Also incorrect use of.Text; should be txtState.Clear()


Download ppt "Chapter 21 Creating Applications with Visual Basic.NET Chapter 2."

Similar presentations


Ads by Google