Sie sind auf Seite 1von 11

KnowledgeSystemsInstituteGraduateSchoolCIS310IntroductiontoProgramming(VisualBasic) BuildingtheDirectionsApplication

BuildingtheDirectionsApplication

Step1
Definewhattheapplicationistodo Purpose:DisplayamaptotheHighlanderHotel Input:None Process:Displayaform Output:Displayontheformagraphicimageshowingamap

Step2
VisualizetheApplicationandDesignItsUserInterface

Page1of11

KnowledgeSystemsInstituteGraduateSchoolCIS310IntroductiontoProgramming(VisualBasic) BuildingtheDirectionsApplication

Step3
Determinethecontrolsneeded

Step4
Definerelevantpropertyvaluesforeachcontrol Form o o Name:Form1 Text:"Directions"

Label o o o o Name:Label1 Text:"DirectionstotheHighlanderHotel" TextAlign:MiddleCenter Font:Microsoftsansserif,bold,18point

PictureBox o o o Name:PictureBox1 Picture:HotelMap.jpg SizeMode:StretchImage

Page2of11

KnowledgeSystemsInstituteGraduateSchoolCIS310IntroductiontoProgramming(VisualBasic) BuildingtheDirectionsApplication Step5 CreatetheFormsandOtherControlsUsingVisualBasic EstablishtheFormandsetitsTextproperty AddaLabelcontrol o o Positionandresizeitontheform SetText,TextAlign,andFontproperties

AddaPictureBoxcontrol o o Positionandresizeitontheform SetImagepropertytodisplayHotelMap.jpg

Runtheapplication Closeandsavetheapplication

Page3of11

KnowledgeSystemsInstituteGraduateSchoolCIS310IntroductiontoProgramming(VisualBasic) BuildingtheDirectionsApplication

ModifytheDirectionsApplication
TheHighlanderHotelmanagerwouldlikeyoutoaddthefollowingitemstotheapplication: ALabelcontainingthewrittendirections AButtontodisplaythedirections AButtontoexittheapplication

Page4of11

KnowledgeSystemsInstituteGraduateSchoolCIS310IntroductiontoProgramming(VisualBasic) BuildingtheDirectionsApplication

Step1
ControlstobeAdded

Step2
ControlProperties Label o o o Name:lblDirections Text:TravelingonI89,etc Visible:False

Button o o Name:btnDisplayDirections Text:DisplayDirections

Button o o Name:btnExit Text:Exit

Page5of11

KnowledgeSystemsInstituteGraduateSchoolCIS310IntroductiontoProgramming(VisualBasic) BuildingtheDirectionsApplication

Step3
TheCodeWindow Doubleclickingacontrolindesignmode: opensthecodewindow createsacodetemplateforthecontrolseventhandlerwhereyoufillinthecodefortheevent

Step4
TheClickEventHandlerforbtnDisplayDirections

Page6of11

KnowledgeSystemsInstituteGraduateSchoolCIS310IntroductiontoProgramming(VisualBasic) BuildingtheDirectionsApplication

Step5
ChangingaControlsVisiblePropertyinCode Specifythecontrolname(lblDirections) Thenadot ThenthePropertyName(Visible) Forexample: o o o lblDirections.Visible referstotheVisiblepropertyofthelblDirectionscontrol Thevisiblepropertyvaluesmayonlybetrueorfalse

Step6
TheAssignmentStatement Specifytheitemtoreceivethevalue Thentheequalsymbol Thenthevaluetobeassigned Forexample: o o o lblDirections.Visible=True AssignsthevalueTruetotheVisiblepropertyofthelblDirectionscontrol CausesthetextofthelblDirectionscontroltobecomevisibletotheuser

Page7of11

KnowledgeSystemsInstituteGraduateSchoolCIS310IntroductiontoProgramming(VisualBasic) BuildingtheDirectionsApplication

Step7
TheClickEventHandlerforbtnExit

Page8of11

KnowledgeSystemsInstituteGraduateSchoolCIS310IntroductiontoProgramming(VisualBasic) BuildingtheDirectionsApplication

Step8
UseVisualBasictoUpdatetheApplication Placethelabelandthebuttonsontheform Enterthecodeforthetwoprocedures Testtheapplication

Page9of11

KnowledgeSystemsInstituteGraduateSchoolCIS310IntroductiontoProgramming(VisualBasic) BuildingtheDirectionsApplication

ModifytheDirectionsApplicationForFun!

Controlstobeaddedandproperties Button o o Name:btnHideDirections Text:HideDirections

Button o Name:btnDisplayHideDirections

Page10of11

KnowledgeSystemsInstituteGraduateSchoolCIS310IntroductiontoProgramming(VisualBasic) BuildingtheDirectionsApplication
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lblDirections.Visible = False btnDisplayDirections.Enabled = True btnHideDirections.Enabled = False btnDisplayHideDirections.Text = "Display Directions" btnDisplayHideDirections.BackColor = Color.OrangeRed btnDisplayHideDirections.ForeColor = Color.White End Sub Private Sub btnDisplayDirections_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayDirections.Click ' Make the directions visible. lblDirections.Visible = True btnDisplayDirections.Enabled = False btnHideDirections.Enabled = True btnDisplayHideDirections.Text = "Hide Directions" btnDisplayHideDirections.BackColor = Color.Green End Sub Private Sub btnHideDirections_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHideDirections.Click ' Make the directions invisible. lblDirections.Visible = False btnDisplayDirections.Enabled = True btnHideDirections.Enabled = False btnDisplayHideDirections.Text = "Display Directions" btnDisplayHideDirections.BackColor = Color.OrangeRed End Sub Private Sub btnDisplayHideDirections_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayHideDirections.Click If lblDirections.Visible = False Then lblDirections.Visible = True btnDisplayDirections.Enabled = False btnHideDirections.Enabled = True btnDisplayHideDirections.Text = "Hide Directions" btnDisplayHideDirections.BackColor = Color.Green Else lblDirections.Visible = False btnDisplayDirections.Enabled = True btnHideDirections.Enabled = False btnDisplayHideDirections.Text = "Display Directions" btnDisplayHideDirections.BackColor = Color.OrangeRed End If End Sub Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click ' Close the form. Me.Close() End Sub End Class

Page11of11

Das könnte Ihnen auch gefallen