SlidePub
Home
Categories
Login
Register
Home
Technology
chap005 (1) dialogue box menus presentattion
chap005 (1) dialogue box menus presentattion
arulrajvetias
21 views
34 slides
Sep 10, 2024
Slide
1
of 34
Previous
Next
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
About This Presentation
vb
Size:
496.6 KB
Language:
en
Added:
Sep 10, 2024
Slides:
34 pages
Slide Content
Slide 1
Chapter 5Chapter 5
Menus, Common Dialog Menus, Common Dialog
Boxes, Sub Procedures Boxes, Sub Procedures
andand
Function ProceduresFunction Procedures
Programming InProgramming In
Visual Basic .NETVisual Basic .NET
Slide 2
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 2
<ALT><F><ALT><F>
MenuMenu
Menu ItemsMenu Items
Slide 3
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 3
MenusMenus
•Menu BarMenu Bar
–Contains menus which drop down to display list of Contains menus which drop down to display list of
menu itemsmenu items
•Each item has a name and text propertyEach item has a name and text property
•Each item has a click eventEach item has a click event
•Add MainMenu control to formAdd MainMenu control to form
–Appears in the Component Tray, below form, where Appears in the Component Tray, below form, where
nondisplay controls are shownnondisplay controls are shown
–Words "Words "Type HereType Here" appear at the top of the form" appear at the top of the form
Slide 4
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 4
Menus (continued)Menus (continued)
Type first Menu hereType first Menu here
MainMenu Control MainMenu Control
appears in appears in
Component TrayComponent Tray
Slide 5
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 5
Defining MenusDefining Menus
•To create the menus simply type where the words "To create the menus simply type where the words "Type Type
HereHere" appear at the top of the form" appear at the top of the form
•Include & symbol as you type to indicate keyboard access Include & symbol as you type to indicate keyboard access
keyskeys
•You are actually entering the Text property for a You are actually entering the Text property for a
MenuItem objectMenuItem object
•Change MenuItem object names in the Properties window Change MenuItem object names in the Properties window
and follow consistent naming conventionsand follow consistent naming conventions
Slide 6
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 6
Submenus Submenus
•Pop up to the right of a menu itemPop up to the right of a menu item
•Filled triangle to the right of the menu item indicates to the Filled triangle to the right of the menu item indicates to the
user the existence of a submenuuser the existence of a submenu
•Create submenus by moving to the right of a menu item Create submenus by moving to the right of a menu item
and typing the next item's textand typing the next item's text
Slide 7
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 7
Submenus Submenus (continued)(continued)
Slide 8
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 8
Separator BarsSeparator Bars
•Used for grouping menu items according to their purposeUsed for grouping menu items according to their purpose
•Visually represented as a bar across the menuVisually represented as a bar across the menu
•Create using one of two methodsCreate using one of two methods
–Typing a single hyphen for the textTyping a single hyphen for the text
–Right-click on Menu Designer where you want a Right-click on Menu Designer where you want a
separator bar and choose Insert Separatorseparator bar and choose Insert Separator
Slide 9
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 9
Coding for Menu ItemsCoding for Menu Items
•Double-click any menu item to open the item’s click event Double-click any menu item to open the item’s click event
procedureprocedure
•Write code for the click event procedureWrite code for the click event procedure
Slide 10
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 10
Modifying Menu ItemsModifying Menu Items
•Right-click the Menu Bar to:Right-click the Menu Bar to:
–DeleteDelete
–Insert NewInsert New
–Insert SeparatorInsert Separator
–Edit NamesEdit Names
•Displays menu item Name property rather than Text Displays menu item Name property rather than Text
property on formproperty on form
•Drag and Drop menu items to new locationsDrag and Drop menu items to new locations
Slide 11
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 11
Menu PropertiesMenu Properties
•Enabled property, True/FalseEnabled property, True/False
•Checked property, True/FalseChecked property, True/False
–Used to indicate current state of menu item that can be Used to indicate current state of menu item that can be
turned on and offturned on and off
•Create keyboard shortcutsCreate keyboard shortcuts
–In Properties window for menu item, select the Shortcut In Properties window for menu item, select the Shortcut
propertyproperty
–Make choice from drop-down listMake choice from drop-down list
Slide 12
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 12
Standards for Windows MenusStandards for Windows Menus
•Follow Windows standards for applicationsFollow Windows standards for applications
•Include keyboard access keysInclude keyboard access keys
•Use standards for shortcut keys, if usedUse standards for shortcut keys, if used
•Place File menu at left end of menu bar and end File menu Place File menu at left end of menu bar and end File menu
with Exitwith Exit
•Help, if included, is placed at right end of menu barHelp, if included, is placed at right end of menu bar
FFile ile EEdit dit VView Formaiew Formatt HHelpelp
Slide 13
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 13
Common Dialog BoxesCommon Dialog Boxes
•Predefined standard dialog boxes for:Predefined standard dialog boxes for:
–File Opening and SavingFile Opening and Saving
–Font and Color selectionFont and Color selection
–Printing and PreviewingPrinting and Previewing
•Add appropriate Common Dialog control to formAdd appropriate Common Dialog control to form
–Appears in the Component TrayAppears in the Component Tray
Slide 14
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 14
Common Dialog ControlsCommon Dialog Controls
•OpenFileDialogOpenFileDialog
•SaveFileDialogSaveFileDialog
•FontDialogFontDialog
•ColorDialogColorDialog
•PrintDialogPrintDialog
•PrintPreviewDialogPrintPreviewDialog
Slide 15
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 15
Component trayComponent tray
Common dialog controlsCommon dialog controls
Slide 16
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 16
Displaying a Windows Common Dialog Displaying a Windows Common Dialog
BoxBox
•Use ShowDialog method to display the common dialog Use ShowDialog method to display the common dialog
box at run timebox at run time
•ShowDialog only displays the dialog, it does not do ShowDialog only displays the dialog, it does not do
anything elseanything else
ColorDialog1.ShowDialog( )ColorDialog1.ShowDialog( )
FontDialog1.ShowDialog( )FontDialog1.ShowDialog( )
Slide 17
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 17
CodeCode
With OpenFileDialog1With OpenFileDialog1
.ShowDialog().ShowDialog()
End WithEnd With
Slide 18
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 18
Using the Information from the Dialog Using the Information from the Dialog
BoxBox
•Code must be written to retrieve and use the choice made Code must be written to retrieve and use the choice made
by the user in the common dialog boxby the user in the common dialog box
•ExampleExample
–Color Dialog displayedColor Dialog displayed
–User selects color and clicks OKUser selects color and clicks OK
–Code must be written to apply the selected color to the Code must be written to apply the selected color to the
object(s)object(s)
titleLabel.BackColor = ColorDialog1.Color
Slide 19
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 19
Color and Font DialogsColor and Font Dialogs
Slide 20
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 20
Setting Initial ValuesSetting Initial Values
•Before executing the ShowDialog method, assign the Before executing the ShowDialog method, assign the
existing values of the object's properties that will be existing values of the object's properties that will be
alteredaltered
•When the dialog box appears, the current values will be When the dialog box appears, the current values will be
selectedselected
•If the user presses Cancel, property settings for the objects If the user presses Cancel, property settings for the objects
will remain unchangedwill remain unchanged
FontDialog1.Font = subTotalLabel.Font FontDialog1.Font = subTotalLabel.Font or or
ColorDialog1.Color = Me.BackColorColorDialog1.Color = Me.BackColor
Slide 21
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 21
Creating Context MenusCreating Context Menus
•Shortcut menus that pop up when you right-clickShortcut menus that pop up when you right-click
•Are specific to the component to which user is pointing, Are specific to the component to which user is pointing,
reflecting options available for that component or situationreflecting options available for that component or situation
•A context menu does not have a top level menuA context menu does not have a top level menu
•Application can have multiple context menusApplication can have multiple context menus
Slide 22
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 22
Creating Context Menus (continued)Creating Context Menus (continued)
•Add ContextMenu component to the formAdd ContextMenu component to the form
–Appears in the Component TrayAppears in the Component Tray
•Click on the words "Click on the words "Context MenuContext Menu", at the top of the form, ", at the top of the form,
the words "the words "Type HereType Here" appear" appear
•Click on the words "Click on the words "Type HereType Here" and proceed as you did for " and proceed as you did for
the main menuthe main menu
Slide 23
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 23
Connecting the Context Menu to a Form Connecting the Context Menu to a Form
or Objector Object
•Set the form or object’s ContextMenu property to the Set the form or object’s ContextMenu property to the
name of the ContextMenuname of the ContextMenu
•If there is more than one context menu defined, If there is more than one context menu defined,
choose from the listchoose from the list
•Add to the Handles clause of a MainMenu item to use Add to the Handles clause of a MainMenu item to use
the same procedure for a related ContextMenu itemthe same procedure for a related ContextMenu item
Slide 24
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 24
Writing General ProceduresWriting General Procedures
•A general procedure is reusable code which can be called A general procedure is reusable code which can be called
from multiple proceduresfrom multiple procedures
•Useful for breaking down large sections of code into Useful for breaking down large sections of code into
smaller unitssmaller units
•Two typesTwo types
–Sub Procedure performs actionsSub Procedure performs actions
–Function performs actions AND returns a value (the Function performs actions AND returns a value (the
return valuereturn value))
Slide 25
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 25
Creating a New Sub ProcedureCreating a New Sub Procedure
•In the Editor window enclose the lines of code with a set of In the Editor window enclose the lines of code with a set of
Private Sub and End Sub statementsPrivate Sub and End Sub statements
•To use the Sub Procedure, call it from another procedureTo use the Sub Procedure, call it from another procedure
•Code in a Sub Procedure cannot be executed unless called Code in a Sub Procedure cannot be executed unless called
from another procedurefrom another procedure
Private Sub ProcedureName( )
' Statements in the procedure.
End Sub
Slide 26
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 26
Passing Arguments to Procedures Passing Arguments to Procedures
(page 205)(page 205)
•Declare variable as local and pass to any called proceduresDeclare variable as local and pass to any called procedures
•If a sub procedure names an argument, any call to the procedure If a sub procedure names an argument, any call to the procedure
must supply the argumentmust supply the argument
•Name of local variable does not need to match name in sub Name of local variable does not need to match name in sub
procedure argument listprocedure argument list
•Number of arguments, sequence and data type must matchNumber of arguments, sequence and data type must match
Slide 27
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 27
Passing Arguments ByVal or ByRefPassing Arguments ByVal or ByRef
•ByVal (default)ByVal (default)
–Sends a copy, original cannot be alteredSends a copy, original cannot be altered
•ByRefByRef
–Sends a reference to the memory location where the Sends a reference to the memory location where the
original is stored and therefore the original can be original is stored and therefore the original can be
alteredaltered
•Examples page 206Examples page 206
Slide 28
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 28
Sub Procedure ExampleSub Procedure Example
Private Sub SelectColor(incomingColor As Color)
With ColorDialog1
.Color = incomingColor
.ShowDialog( )
End With
End Sub
Private Sub changeTitleButtonColor_Click( )
Dim originalColor As Color
originalColor = titleLabel.ForeColor
SelectColor(originalColor)
titleLabel.ForeColor = ColorDialog1.Color
End Sub
Sub Procedure
Calling
Procedure
Slide 29
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 29
Writing Function ProceduresWriting Function Procedures
•In the Editor window enclose the linesIn the Editor window enclose the lines
of code with Private Function( ) and End Function of code with Private Function( ) and End Function
statementsstatements
•To use the Function, Call it by using it in an expressionTo use the Function, Call it by using it in an expression
•Pass arguments ByVal or ByRefPass arguments ByVal or ByRef
Private Function FunctionName( ) As Datatype
' Statements to execute.
End Function
Slide 30
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 30
Returning the Result of a FunctionReturning the Result of a Function
•To return a value to the calling procedure set up a return To return a value to the calling procedure set up a return
valuevalue
•The return value will be placed by VB in a variable with The return value will be placed by VB in a variable with
the SAME name as the Function's namethe SAME name as the Function's name
OROR
•Use the Return statement to return the valueUse the Return statement to return the value
Slide 31
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 31
Function ExampleFunction Example
Private Sub calculateButton_Click( )
Dim salesDecimal As Decimal
salesDecimal = Decimal.Parse(salesTextBox.Text)
commissionLabel.Text = Commission(salesDecimal.ToString("C"))
End Sub
Calling
Procedure
Private Function Commission(ByVal salesAmountDecimal As Decimal) _
As Decimal
If salesAmountDecimal < 100D Then
Commission = 0D
Else
Commission = 0.15 * salesAmountDecimal
End If
End Function
Function
Slide 32
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 32
Functions with Multiple ArgumentsFunctions with Multiple Arguments
•Functions can receive one or more arguments (values)Functions can receive one or more arguments (values)
•Sequence and data type of arguments in Call must exactly match Sequence and data type of arguments in Call must exactly match
arguments in function headerarguments in function header
Private Function Payment(ByVal rateDecimal As Decimal, _
ByVal timeDecimal As Decimal, ByVal amountDecimal _
As Decimal) As Decimal
paymentLabel.Text = Payment(Decimal.Parse(rateTextBox.Text), _
Decimal.Parse(yearsTextBox.Text), _
Decimal.Parse(principalTextBox.Text)).ToString( )
End Function
Slide 33
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 33
Breaking Calculations into Smaller Breaking Calculations into Smaller
UnitsUnits
•Projects with many calculations are easier to understand Projects with many calculations are easier to understand
and write if calculations are broken into small unitsand write if calculations are broken into small units
•Each unit should perform one program function or logic Each unit should perform one program function or logic
blockblock
Slide 34
© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.5- 34
Tags
Categories
Technology
Download
Download Slideshow
Get the original presentation file
Quick Actions
Embed
Share
Save
Print
Full
Report
Statistics
Views
21
Slides
34
Age
449 days
Related Slideshows
11
8-top-ai-courses-for-customer-support-representatives-in-2025.pptx
JeroenErne2
48 views
10
7-essential-ai-courses-for-call-center-supervisors-in-2025.pptx
JeroenErne2
47 views
13
25-essential-ai-courses-for-user-support-specialists-in-2025.pptx
JeroenErne2
37 views
11
8-essential-ai-courses-for-insurance-customer-service-representatives-in-2025.pptx
JeroenErne2
34 views
21
Know for Certain
DaveSinNM
22 views
17
PPT OPD LES 3ertt4t4tqqqe23e3e3rq2qq232.pptx
novasedanayoga46
26 views
View More in This Category
Embed Slideshow
Dimensions
Width (px)
Height (px)
Start Page
Which slide to start from (1-34)
Options
Auto-play slides
Show controls
Embed Code
Copy Code
Share Slideshow
Share on Social Media
Share on Facebook
Share on Twitter
Share on LinkedIn
Share via Email
Or copy link
Copy
Report Content
Reason for reporting
*
Select a reason...
Inappropriate content
Copyright violation
Spam or misleading
Offensive or hateful
Privacy violation
Other
Slide number
Leave blank if it applies to the entire slideshow
Additional details
*
Help us understand the problem better